#include
#include <stdlib.h>
using namespace std;
typedef struct Node
{
int data;
struct Node* next;
}Node;
void initList(Node* hNode)
{
hNode = new Node;
hNode -> next = NULL;
}
void creatList(Node* hNode)
{
Node* tNode = hNode;
int Length;
cout << "请输入链表的长度:";
cin >> Length;
cout << "请输入链表的数据:";
for(int i = 0; i < Length; i++)
{
Node* cNode = new Node;
cNode -> next = NULL;
cin >> cNode -> data;
tNode -> next = cNode;
tNode = cNode;
}
}
void printList(Node* hNode)
{
Node* p;
p = hNode -> next;
cout << "输出链表中的数据元素:" << endl;
while(p)
{
cout << p->data << " ";
p = p -> next;
}
}
int main(void)
{
Node* Mylist;
initList(Mylist);
creatList(Mylist);
printList(Mylist);
return 0;
}
这个错误有什么解决的方法