C
chirag
hi i have following code. i m confused about where do i write p-> next
=NULL once user enters
-1 to exit. help is appriciated. because what i have right now it sets =
NULL after the first integer.
#include <iostream>
#include <cassert>
using std::cin;
using std::cout;
using std::endl;
struct Node
// Definition of Node type
{
int item;
Node *next;
};
Node *enterNewLinkedList()
// Reads a series of integers from the keyboard (ending with -1) and
// returns a pointer to a linked list containing those integers, or
// NULL if the list is empty. No error checking is done.
{
int a;
cout<<"Enter a series of integers :"<<endl;
cin>>a;
if ( a!=-1)
{
Node *p;
p = new Node;
(*p).item = a;
p->item = a;
p->next= new Node;
p->next=NULL;
}
}
=NULL once user enters
-1 to exit. help is appriciated. because what i have right now it sets =
NULL after the first integer.
#include <iostream>
#include <cassert>
using std::cin;
using std::cout;
using std::endl;
struct Node
// Definition of Node type
{
int item;
Node *next;
};
Node *enterNewLinkedList()
// Reads a series of integers from the keyboard (ending with -1) and
// returns a pointer to a linked list containing those integers, or
// NULL if the list is empty. No error checking is done.
{
int a;
cout<<"Enter a series of integers :"<<endl;
cin>>a;
if ( a!=-1)
{
Node *p;
p = new Node;
(*p).item = a;
p->item = a;
p->next= new Node;
p->next=NULL;
}
}