#include<stdio.h>
#include<stdlib.h>
struct Node{
int Data;
struct Node *Next;
};
struct Node *create(){
struct Node *head;
head=(struct Node *)malloc(sizeof(struct Node));
head->Next=NULL;
return head;
}
void tail_insert(struct Node *head,int num){
struct Node *p,*q;
p=head;
while(p->Next!=NULL){
p=p->Next;
}
q=(struct Node *)malloc(sizeof(struct Node));
q->Data=num;
q->Next=p->Next;
p->Next=q;
}
void show(struct Node *head){
struct Node *p;
p=head->Next;
while(p!=NULL){
printf("%d\t",p->Data);
p=p->Next;
}
}
int main(){
struct Node *head;
head=create();
int temp;
for(int i=0;i<10;i++){
scanf("%d",&temp);
tail_insert(head,temp);
}
show(head);
return 0;
}
从键盘输入10个整数放入链表,要求链表中的元素与输入顺序一致,然后输出该链表。(C语言)
最新推荐文章于 2023-03-16 15:52:43 发布