Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- void clear();
- void pressAnyKey();
- struct node
- {
- int data;
- node*next;
- };
- node*head=NULL;
- node*create_node(int x)
- {
- node*newnode=new node;
- newnode->data=x;
- newnode->next=NULL;
- return newnode;
- }
- void insert_beg(int x)
- {
- node*newnode=create_node(x);
- {
- if(head==NULL)
- {
- head=newnode;
- return ;
- }
- else
- {
- newnode->next=head;
- head=newnode;
- }
- }
- }
- void display()
- {
- node*temp=head;
- if(head==NULL)
- {
- cout<<"list is empty";
- return;
- }
- while(temp!=NULL)
- {
- cout<<temp->data<<"\n";
- temp=temp->next;
- }
- }
- void insert_last(int x)
- {
- node*newnode=create_node(x);
- node*temp=head;
- while(temp->next!=NULL)
- temp=temp->next;
- temp->next=newnode;
- }
- int main()
- {
- int ch;
- while(true){
- clear();
- cout<<" list "<<endl;
- cout<<" 1-begain "<<endl;
- cout<<" 2-display "<<endl;
- cin>>ch;
- switch (ch)
- {
- case 1:
- clear();
- int x;
- cout<<"enter"<<endl;
- cin>>x;
- insert_beg(x);
- break;
- case 2:
- clear();
- display();
- break;
- default:
- clear();
- cout<<"invalid choice\n";
- }
- pressAnyKey();
- }
- return 0;
- }
- void clear(){
- system("cls") ;
- }
- void pressAnyKey(){
- cout<<"\n\n\n press any key to back to main menu...\n\n";
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement