链表排序错在哪啊???
来源:百度知道 编辑:UC知道 时间:2024/06/10 19:22:22
#include "stdio.h"
#include <stdlib.h>
#include <time.h>
enum Status{OK,ERROR};
typedef int ElemType;
typedef struct LNode
{
ElemType data;///链表结点的元素,类型为int
LNode *next;//指向下一结点指针
}LNode,*LinkList;
Status CreatLink(LinkList &L,int n)///建立链表
{
LinkList p;
LinkList Head;
int i;
L = (LinkList)malloc(sizeof(LNode));///链表头结点
L->next = NULL;
Head = L;
if (L == NULL)
{
return ERROR;
}
for (i = 0; i < n; ++i)
{
p = (LinkList)malloc(sizeof(LNode));///产生新结点
if (p == NULL)
{
return ERROR;
}
printf("please input a number:\n");
scanf("%d",&p->data);
p->next = NULL;
Head->next = p;//尾插法插入新结点
Head = p;
}
return OK;
}
Status SortLink(LinkList &L)
{
LinkList P;
#include <stdlib.h>
#include <time.h>
enum Status{OK,ERROR};
typedef int ElemType;
typedef struct LNode
{
ElemType data;///链表结点的元素,类型为int
LNode *next;//指向下一结点指针
}LNode,*LinkList;
Status CreatLink(LinkList &L,int n)///建立链表
{
LinkList p;
LinkList Head;
int i;
L = (LinkList)malloc(sizeof(LNode));///链表头结点
L->next = NULL;
Head = L;
if (L == NULL)
{
return ERROR;
}
for (i = 0; i < n; ++i)
{
p = (LinkList)malloc(sizeof(LNode));///产生新结点
if (p == NULL)
{
return ERROR;
}
printf("please input a number:\n");
scanf("%d",&p->data);
p->next = NULL;
Head->next = p;//尾插法插入新结点
Head = p;
}
return OK;
}
Status SortLink(LinkList &L)
{
LinkList P;
#include "stdio.h"
#include <stdlib.h>
#include <time.h>
typedef int ElemType;
我不会解释,比较笨,你可以自己百度一下 链表排序 关键字 有人讲解的很详细的 你把思想搞懂了在自己写一遍, 你的那个for 最好换成while 感觉这样看着舒服一点
typedef struct Node
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
LinkList CreatLink(LinkList L,int n)
{
LinkList p;
LinkList Head;
int i;
L = (LinkList)malloc(sizeof(LNode));
if(!L)
{
printf("fen pei neichun chucuo!!\n");
exit(0);
getch();
}
L->next = NULL;
Head = L;
for (i = 0; i < n; i++)
{
p = (LinkList)malloc(sizeof(LNode));
if (!L)
{
printf("fen pei neichun chucuo!!\n");
exit(0);
getch();
}
printf("please input a number:\n");
scanf("%d",&p->data);
p->next = NULL;
L->next