单链表这里到底错什么地方了?运行了很多次了~

来源:百度知道 编辑:UC知道 时间:2024/05/22 16:00:33
错的地方已经加了注释了~搞定为什么运行成功以后15分奉上~
程序功能是单链表输入数据然后逆转~

#include "stdio.h"
#include "malloc.h"
typedef int elemtype

typedef struct node/*这里究竟错什么地方啊,难道定义错了?*/
{elemtype data;
struct node*next;
}linklist;

linklist *creatlinklist()/*这里呢,错什么地方?*/
{int x;
linklist *p,*q,*head;
head=( linklist *)malloc(sizof(linklist));
head->next=NULL;
p=head;
scanf("%d",&x);
while(x!=-1)
{q=( linklist *)malloc(sizof(linklist));
q->data=x;q->next=NULL;
p->next=q;p=p->next;
scanf("%d",&x);}
return head;
}

void reverse(linklist *H)
{
linklist *p,*q;
p=H->next;
H->next=NULL;
while(p!=NULL)
{q=p;
p=p->next;
q->next=H->next;
H->next=q;
}
}

void main()
{linklist *p,*head;
printf("please input data:\n");
head

#include <stdio.h>
#include <malloc.h>
#define elemtype int

typedef struct Lnode/*这里究竟错什么地方啊,难道定义错了?*/
{
elemtype data;
struct Lnode *next;
}Lnode,*Linklist;

Linklist creatlinklist()/*这里呢,错什么地方?*/
{
int x;
Linklist head;
struct Lnode *p,*q;
head=(Linklist)malloc(sizeof(struct Lnode));
head->next=NULL;
p=head;
scanf("%d",&x);
while(x!=-1)
{
q=malloc(sizeof(struct Lnode));
q->data=x;q->next=NULL;
p->next=q;p=p->next;
scanf("%d",&x);
}
return head;
}

void reverse(Linklist H)
{

Linklist p,q;
p=H->next;
H->next=NULL;
while(p!=NULL)
{
q=p;
p=p->next;
q->next=H->next;
H->next=q;
}
}