#include <stdio.h>
#include <stdlib.h>
typedef struct List{
int data;
struct List *next;
}List;
List * creatList(List *head,int data)
{
if(head == NULL)
{
head = (List*)malloc(sizeof(List));
head->next = NULL;
}
else
{
List *Node = (List*)malloc(sizeof(List));
Node->next = head->next;
Node->data = data;
head->next = Node;
}
return head;
}
void travel1_List(List *head)
{
head = head->next;
while(head)
{
printf("%d ",head->data);
head = head->next;
}
}
int travel_List(List *head,int str[])
{
int i=0;
head = head->next;
while(head)
{
str[i++] = head->data;
head = head->next;
}
return i;
}
int main(void)
{
List * head = NULL;
int str[10]={0};
int i;
int num;
srand(time(NULL));
for(i=0;i<=10;i++)
{
head = creatList(head,rand()%15);
}
travel1_List(head);
num = travel_List(head,str);
printf("num = %d\n",num);
for(i=num-1;i>=0;i--)
{
printf("%d ",str[i]);
}
return 0;
}