编程打卡:C++ 语言程序设计
#include <iostream>
#include <array>
using namespace std;
int main()
{
int n;
cin >> n;
array<double, 100000> scores;
for (int i = 0; i < n; i++)
{
cin >> scores[i];
}
double average = 0;
for (int i = 0; i < n; i++)
{
average += scores[i];
}
average /= n;
cout << average << endl;
}
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node *next;
Node(int d = 0, Node *n = NULL) : data(d), next(n) {}
};
class List
{
private:
Node *head;
public:
List() : head(NULL) {}
~List();
void insert(int d);
void print();
void insertList(List &l);
};
List::~List()
{
Node *p = head;
while (p != NULL)
{
head = p->next;
delete p;
p = head;
}
}
void List::insert(int d)
{
Node *p = new Node(d);
p->next = head;
head = p;
}
void List::print()
{
Node *p = head;
while (p != NULL)
{
cout << p->data << " ";
p = p->next;
}
}
void List::insertList(List &l)
{
Node *p = l.head;
while (p != NULL)
{
insert(p->data);
p = p->next;
}
}
int main()
{
List A, B;
for (int i = 0; i < 5; i++)
{
A.insert(i);
B.insert(i + 5);
}
cout << "A: ";
A.print();
cout << endl;
cout << "B: ";
B.print();
cout << endl;
A.insertList(B);
cout << "A: ";
A.print();
cout << endl;
return 0;
}
This is a Test
标签:Node,head,int,void,编程,List,C++,next,打卡 From: https://www.cnblogs.com/sugar-refinery/p/17383087.html