You are on page 1of 2

#include <iostream>

using namespace std;

struct Node;
typedef struct Node * PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
struct Node
{
int e;
Position next;
};
void Insert(int x, List l)
{
Position TmpCell;
TmpCell = new Node;
if(TmpCell == NULL)
cout << "Memory out of space\n" ;
else
{
TmpCell->e = x;
TmpCell->next = l->next;
l->next = TmpCell;
}
}
void Display(List l)
{
cout << "The list element are :: ";
Position p = l->next;
while(p != NULL)
{
cout << p->e << "->";
p = p->next;
}
}
main()
{
int x, pos, ch, i;
List l;
l = new Node;
l->next = NULL;
List p = l;
cout << "LINKED LIST IMPLEMENTATION \n\n" ;
do
{
cout << "\n\n1. INSERT 2. DISPLAY 3. QUIT\n\nEnter the choice :: ";
cin >> ch;
switch(ch)

{
case 1:
p = l;
cout << "Enter the element to be inserted :: ";
cin >> x;
Insert(x,l);
break;
case 2:
Display(l);
break;
}
} while(ch<3);
}

You might also like