#include<stdio.h>
#include<stdlib.h>
#define CardNum 13
typedef struct Node
{
int data;
struct Node *next;
}Node;
void CreateList(Node **list ,int n = CardNum)
{
Node *head = (Node*)malloc(sizeof(Node));
head->next = NULL;
Node* p =head;
Node* s ;
while( n--)
{
s = (Node*)malloc(sizeof(Node));
s->data = n;
p->next = s;
p = s;
}
// s->next=NULL; //线性链表时,这点不设在print中引发异常
s->next = head->next;
*list = head->next;
free(head);
}
void print(Node* list)
{
Node* p =list;
do
{
printf("%d ",p->data);
p=p->next;
}while(p != list);
printf("\n");
}
void main()
{
Node* list;
CreateList(&list);
print(list);
}