主题:帮我看看一个链表的程序
刚写了几个函数就指针出错,找不到错误,请高手给看看
编译环境 vc++2005
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include"stdlib.h"
enum Status {OK,ERROR};
typedef int ElemType;
typedef struct LNode
{
ElemType elem;
struct LNode *next;
} Node;
typedef struct
{
Node *head;
Node *tail;
int length;
} LinList;
void MakeNode(Node *pNode,ElemType e)
{
pNode=(Node*)malloc(sizeof(Node));
pNode->next=NULL;
pNode->elem=e;
}
void Free(Node *pNode)
{
}
void InitList(LinList *pList)
{
MakeNode(pList->head,0);
pList->tail=pList->head;
pList->length=0;
}
void ClearList(LinList *pList)
{
pList->length=0;
}
void DestroyList(LinList *pList)
{
free(pList->head);
}
void InsFirst(LinList *pList,Node *pNewNode)
{
if(pList->length==0)
{
pList->head->next=pNewNode;
pNewNode->next=NULL;
}
else
{
pNewNode->next=pList->head->next;
pList->head->next=pNewNode;
}
(pList->length)++;
}
void ListShow(LinList List)
{
Node *p=(List.head)->next;
while(p!=NULL)
{
printf("%d\t",p->elem);
p=p->next;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
LinList MyList;
InitList(&MyList);
Node *pNewNode_1;
MakeNode(pNewNode_1,1);
//InsFirst(&MyList,NewNode_1);
//ListShow(MyList);
return 0;
}
编译环境 vc++2005
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include"stdlib.h"
enum Status {OK,ERROR};
typedef int ElemType;
typedef struct LNode
{
ElemType elem;
struct LNode *next;
} Node;
typedef struct
{
Node *head;
Node *tail;
int length;
} LinList;
void MakeNode(Node *pNode,ElemType e)
{
pNode=(Node*)malloc(sizeof(Node));
pNode->next=NULL;
pNode->elem=e;
}
void Free(Node *pNode)
{
}
void InitList(LinList *pList)
{
MakeNode(pList->head,0);
pList->tail=pList->head;
pList->length=0;
}
void ClearList(LinList *pList)
{
pList->length=0;
}
void DestroyList(LinList *pList)
{
free(pList->head);
}
void InsFirst(LinList *pList,Node *pNewNode)
{
if(pList->length==0)
{
pList->head->next=pNewNode;
pNewNode->next=NULL;
}
else
{
pNewNode->next=pList->head->next;
pList->head->next=pNewNode;
}
(pList->length)++;
}
void ListShow(LinList List)
{
Node *p=(List.head)->next;
while(p!=NULL)
{
printf("%d\t",p->elem);
p=p->next;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
LinList MyList;
InitList(&MyList);
Node *pNewNode_1;
MakeNode(pNewNode_1,1);
//InsFirst(&MyList,NewNode_1);
//ListShow(MyList);
return 0;
}