#include <stdio.h>
#include <stdlib.h>
struct Test
{
int data;
struct Test *next;
};
struct Test *HeadinsertNode(struct Test *head,struct Test *new)
{
if(head == NULL){
head = new;
head->next=NULL;
}else{
new->next = head;
head = new;
}
return head;
}
void printNode(struct Test *head)
{
struct Test *point = head;
while(point != NULL){
printf("%d ",point->data);
point = point->next;
}
putchar('\n');
}
int main()
{
struct Test *head;
head = NULL;
struct Test t1={1,NULL};
struct Test t2={2,NULL};
struct Test t3={3,NULL};
struct Test t4={4,NULL};
struct Test t5={5,NULL};
t1.next = &t2;
t2.next = &t3;
t3.next = &t4;
t4.next = &t5;
printNode(&t1);
head =HeadinsertNode(head,&t1);
head =HeadinsertNode(head,&t2);
head =HeadinsertNode(head,&t3);
head =HeadinsertNode(head,&t4);
head =HeadinsertNode(head,&t5);
printNode(head);
return 0;
}
demo9.10根据头插法逆向排序.c
于 2024-12-05 13:35:27 首次发布