#include<stdio.h>
#include<iostream>
using std::cin;
using std::cout;
class Node {
public:
int data;
Node* next;
Node(int e, Node* n) {
data = e;
next = n;
}
};
Node* createList(int a[],int size) {
Node* head = new Node(0, NULL);
Node* curr = head;
for (int i = 0; i < size; ++i) {
curr->next = new Node(a[i], NULL);
curr = curr->next;
}
return head;
}
void printList(Node* head) {
while (head->next) {
cout << head->next->data << ",";
head = head->next;
}
}
int main() {
int a[6] = { 1,2,3,4,5,6 };
Node* List = createList(a,sizeof(a)/sizeof(int));
printList(List);
}
打印结果