Home > Back-end >  C to establish a simple, singly linked list
C to establish a simple, singly linked list

Time:11-18


I want to build a singly linked list
Issues an error:
Using an uninitialized memory p;
Using an uninitialized local variable p;
Could you tell me how to modify should I?

 # include 
# include
using namespace std;

Struct Node
{
Double data;
Node * next;
};

Void CreateList (Node * & amp; The head)
{
The Node * s, * p;
S=new Node;
Cin & gt;> S - & gt; The data;

While (s - & gt; The data!=0)
{
If (head==NULL)
{
The head=s;
}
The else
{
P - & gt; Next=s;
P=s;
S=new Node;
Cin & gt;> S - & gt; The data;
}
}
P - & gt; Next=NULL;
The delete s;
return;
}

Void ShowNode (Node * head)
{
While (the head)
{
Cout & lt; The head=head - & gt; Next;
}
Cout & lt; }
Int main ()
{
The head Node *=NULL;
CreateList (head);
ShowNode (head);

}
  • Related