#include <iostream>
using namespace std;
class linkedlist
{
public:
struct node
{
int data;
node *next;
}*last, *temp, *head;
// node *last; node *temp; node *head;
public:
void append();
void display();
}l1;
void linkedlist :: append()
{
node *last; node *temp; node *head;
int value;
temp = new node;
cout << "Enter data : ";
cin >> value;
temp->data = value;
temp->next = NULL;
if(head == NULL)
{
head = temp = last;
}
else
{
last->next = temp;
last = temp;
}
cout << "New node created!"<< endl;
}
void linkedlist :: display()
{
temp = head;
while(temp != NULL)
{
cout << temp->data << endl;
temp = temp->next;
}
}
int main()
{
int ch; int choice;
do{
cout << "-----Linked List-----\n\n";
cout << "1. Create first node\n";
cout << "2. Insert new node at the end\n";
cout << "3. Display\n";
cin >> choice;
switch(choice)
{
case 1 : l1.append();
break;
case 2 : l1.append();
break;
case 3 : l1.display();
break;
default : cout << "Enter a valid choice!\n";
}
}
while(ch==1);
cout << "Do you want to continue?\nPress 1 to continue\nPress 0 to exit\n";
cin >> ch;
return 0;
}