编写算法的单链表la,怎么编啊?

来源:百度知道 编辑:UC知道 时间:2024/05/03 06:04:08
编写算法实现单链表的逆置,即要求把单链表la中的数据元素序列(a0,a1,…,an-1)逆置为(an-1,…,a1,a0),并把逆置后的数据元素存储到单链表lb中。

这里我给你一个链表的程序你自己看着遍,总的来说在C语言中链表程序是最难的了!
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct number)

struct number
{ int num;
struct number * next; };

int n;
struct number * creat(void)
{ struct number * head;
struct number * p1,* p2;
n=0;
p1=p2=(struct number *)malloc(LEN);
scanf("%d",&p1->num);
head=NULL;
while(p1->num!=0)
{ n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct number *)malloc(LEN);
scanf("%d",&p1->num); }

p2->next=NULL;
return(head);
}

void print( struct number * head)
{ struct number * p;
printf("\n Now,these %d records are:\n",n);
p=head;
if(head!=NULL)
do{ printf("%4d",p->num);