有关了链表的实现,请大家帮忙看一下

tonymong106 2007-04-10 09:38:20
#ifndef _List_H

struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;

List MakeEmpty(List L);
int IsEmpty(List L);
int IsLast(List L);
Position Find(int X,List L);
void Delete(int X,List L);
Position FindPrevious(int X,List L);
void DeleteList(List L);
Position Header(List L);
Position First(List L);
Position Advance(Position P);
int Retrieve(Position P);

#endif

struct Node
{
int Element;
Position Next;
};

#include "list.h"
#include <stdio.h>
#include <stdlib.h>


void main()
{
Position Insert(int X,List L,Position P);
int PrintList(List L);
Position P,L,Head;
int C;
Head=(Position)malloc(sizeof(struct Node));
Head->Next =NULL;
L=Head;
P=L;
while((C=getchar())!=EOF)
{
Insert(C,L,P);
}
PrintList(Head);
}


//return true if L is empty
int IsEmpty(List L)
{
return L->Next==NULL;
}

//return true if P is thr last position in list L

int IsLast(Position P,List L)
{
return P->Next==NULL;
}

//return position of X in L;NULL if not found

Position Find(int X,List L)
{
Position P;
P=L->Next;
while(P!=NULL&&P->Element!=X)
P=P->Next;
return P;
}


//delete first occurrence of X from a list
//assume use of a header node

void Delete(int X,List L)
{
Position P,TmpCell;
P=FindPrevious(X,L);

if(!IsLast(P,L))
{
TmpCell=P->Next;
P->Next=TmpCell->Next;
free(TmpCell);
}
}


//if X is not found ,then next field of returned
//postion is NULL
//assumes a header

Position FindPrevious(int X,List L)
{
Position P;

P=L;
while(P->Next!=NULL&&P->Next->Element!=X)
P=P->Next;
return P;
}


//insert (after legal position P)
//header implementation assued
//parameter L is unused in this implementation

void Insert(int X,List L,Position P)
{
Position TmpCell;
TmpCell=(Position)malloc(sizeof(struct Node));
if(TmpCell==NULL)
printf("out of space!!!!!");
TmpCell->Element=X;
TmpCell->Next=P->Next;
P->Next=TmpCell;
}


//delete all list
void DeleteList(List L)
{
Position P,Tmp;
P=L->Next;
L->Next=NULL;
while(P!=NULL)
{
Tmp=P->Next;
free(P);
P=Tmp;
}
}


//print a list
//header implementtation assued

void PrintList(List Head)
{
Position P;
P=Head;
if(P!=NULL)
do
{
printf("%d",P->Element);
P=P->Next;
}while(P!=NULL);

}
...全文
219 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tonymong106 2007-04-10
  • 打赏
  • 举报
回复
在编译的时候 没有出错 在运行的时候就出错了
list.obj : error LNK2001: unresolved external symbol "int __cdecl PrintList(struct Node *)" (?PrintList@@YAHPAUNode@@@Z)
list.obj : error LNK2001: unresolved external symbol "struct Node * __cdecl Insert(int,struct Node *,struct Node *)" (?Insert@@YAPAUNode@@HPAU1@0@Z)
mochen5460 2007-04-10
  • 打赏
  • 举报
回复
看了,楼主的问题呢?
braveconf 2007-04-10
  • 打赏
  • 举报
回复
定义,声明形式不一致

33,027

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧