在制作Link ADT时,我收到了编译test.c的错误(测试函数的主要代码) 我认为问题来自函数pushFront。
我尝试了很多方法来摆脱错误,但错误信息没有改变。编译头文件时没有错误,没有前端文件的主c文件。
请帮帮我。
#include <stdio.h>
#include <stdlib.h>
#include "ListADT.h"
int main()
{
LIST* LIST=createList();
char* data ;
NODE* NODE=createNode(data);
pushFront(LIST, data);
return;
}
这是发生错误的test.c文件。 当我编译这个文件时,&#34; test.exe停止工作&#34; 实际上我不知道确切的消息,因为我在我的语言中运行了程序。
下面是定义NODE和LIST的结构。
//List ADT Type Defintions
typedef struct node
{
void* dataPtr;
struct node* link;
} NODE;
typedef struct
{
int count;
NODE* pos;
NODE* head;
NODE* rear;
} LIST;
下面是我正在测试的头文件ListADT.h中的一些函数。 我认为错误的根源是前沿。
//=================CreatNode======================
NODE* createNode(void* dataInPtr)
{
NODE* NewNode;
NewNode = (NODE*) malloc (sizeof (NODE));
NewNode->dataPtr = dataInPtr;
NewNode->link=NULL;
}
//========insert a new node to the front of the list===========
void pushFront (LIST* pList, void* dataInPtr)
{
NODE* NewNode;
NewNode = createNode(dataInPtr);
if(pList->count==0)
{
pList->head = NewNode;
pList->rear = NewNode;
}
else
{
NewNode->link = pList->head;
pList->head = NewNode;
}
pList->count++;
}
我真的不擅长编码,我认为这件事情可能非常微不足道。但我找不到它。 请帮帮我。
答案 0 :(得分:0)
试试这个:
NODE *node=createNode(data);
LIST *list=createList();
pushFront(list, data);
并在createNode()
中返回NewNode