自己照着视频仿照着写的,但是运行却不行啊,比较迷茫
#include<iostream>
using namespace std;
typedef struct MyStruct
{
int data;
MyStruct* next;
}L,*LP;
LP CreateList()
{
LP List = new L;
if (List == 0)
{
cout << "链表初始化失败" << endl;
system("pause");
exit(0);
}
List->next =0;
return List;
}
LP CreateNode(int data)
{
LP Node = new L;
Node->data = data;
Node->next = 0;
return Node;
}
//头插法
void InsertListHeadNode(LP List, int data)
{
LP NewNode = CreateNode(data);
NewNode->next = List->next;
List->next = NewNode->next;
}
bool IsEmptyList(LP List)
{
if (List == 0)
{
return 1;
}
return 0;
}
void PrintList(LP List)
{
LP PList = List->next;
while (PList != 0)
{
cout << PList <<" \t"<< endl;
PList = PList->next;
}
}
int main()
{
LP List = CreateList( );
IsEmptyList(List);
CreateNode(5);
InsertListHeadNode(List,4 );
InsertListHeadNode(List, 3);
InsertListHeadNode(List, 6);
InsertListHeadNode(List, 8);
InsertListHeadNode(List, 10);
PrintList(List);
system("pause");
return 0;
}
希望有大佬看到帮忙看看