线性表的遍历c语言创建
时间: 2023-05-27 13:02:23 浏览: 97
线性表(c语言实现).zip
typedef struct node{
int data;
struct node* next;
}Node, *LinkList;
//创建链表
LinkList CreateList(int n){
LinkList head, p;
head = (LinkList)malloc(sizeof(Node));
head->next = NULL;
int i;
for(i = n; i > 0; i--){
p = (LinkList)malloc(sizeof(Node));
scanf("%d", &p->data);
p->next = head->next;
head->next = p;
}
return head->next;
}
//遍历链表
void TraversalList(LinkList p){
while(p != NULL){
printf("%d ", p->data);
p = p->next;
}
}
int main(){
LinkList p = CreateList(5);
TraversalList(p);
return 0;
}
阅读全文