#include <iostream>
//#include <stdio.h>
//#include <conio.h>
using namespace std;
typedef struct node
{
int data;
node *next;
}node;
class linked_list {
node *START, *END;
public:
linked_list() {
START = nullptr;
END = nullptr;
}
void insert_at_the_beginning();
int delete_from_the_end();
void display();
};
void linked_list::insert_at_the_beginning() {
node *new_node = new node;
node *temp;
cout<<"Enter a number";
cin>>new_node->data;
cout<<"Successfully Inserted"<<endl;
if(START == nullptr) {
START = new_node;
END = new_node;
}
new_node->next = START;
START = new_node;
cout<<START<<endl;
temp = START;
}
int linked_list::delete_from_the_end() {
int data;
node *temp, *t;
temp = START;
while(temp != nullptr) {
t = temp;
temp = temp->next;
}
data = temp->data;
delete temp;
t->next = nullptr;
return data;
}
void linked_list::display(){
node* temp;
temp = START;
while (temp!=nullptr)
{
cout<<temp->data<<endl;
temp = temp->next;
}
}
int main() {
int ch;
linked_list a;
//cout<<"1. Insert\n2.Delete\n3.Display\nEnter Your Choice:";
a.insert_at_the_beginning();
a.insert_at_the_beginning();
a.insert_at_the_beginning();
a.insert_at_the_beginning();
a.insert_at_the_beginning();
cout<<a.delete_from_the_end()<<endl;
// cout<<a.delete_from_the_end()<<endl;
//a.display();
// do
// {
// cin>>ch;
// switch(ch) {
// case 1:
// a.insert_at_the_beginning();
// continue;
// case 2:
// cout<<a.delete_from_the_end()<<endl;
// continue;
// case 3:
// a.display();
// continue;
// default:
// cout<<"Wrong Choice";
// }
// cout<<"Enter your choice:";
// } while (ch!=0);
return 0;
}