结构体链表问题 c语言 求教达人

来源:百度知道 编辑:UC知道 时间:2024/06/09 01:20:27
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NULL 0
#define LENG sizeof(struct Lnode)

struct Lnode
{
int data;
struct Lnode *next;
};

struct Lnode *creat()
{
struct Lnode *f,*p,*q,*head;
int e;
head=(struct Lnode *)malloc(LENG);
head->next=NULL;
do{
f=(struct Lnode *)malloc(LENG);
scanf("%d",&e);
f->data=e;
q=head;
p=head->next;
while(p&&e>p->data)
{
q=p;
p=p->next;
}
f->next=p;
q->next=f;
} while(e!=0);
return head;
}

struct Lnode *merge(struct Lnode *la,struct Lnode *lb,struct Lnode *lc)
{

struct Lnode *pa,*pb,*pc,*t;
pc=NULL;
pa=la->next;
pb=lb->next;
pc=lc=la;
t=pc;
free(lb);
while(pa&&pb)
{
if(pa->data<=pb->data)

应你的要求给你改好了。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NULL 0
#define LENG sizeof(struct Lnode)

struct Lnode
{
int data;
struct Lnode *next;
};

struct Lnode *creat()
{
struct Lnode *f,*p,*q,*head;
int e;
char ch,*pstr,str[200];
head=(struct Lnode *)malloc(LENG);
head->next=NULL;

memset(str, 0x00, sizeof(str));
pstr = str;

while(1)
{
ch = getchar();
if(ch == 32 || ch == 10)
{
//读入数据
*pstr = '\0';
e = atoi(str);
memset(str, 0x00, sizeof(str));
pstr = str;

//链表操作
f=(struct Lnode *)malloc(LENG);
f->data=e;
q=head;
p=head->next;
while(p&&e>p->data)
{
q=p;
p=p->next;
}
f->next=p;
q->next=f;
if(ch == 10) break;
}
else *ps