Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Linked List C++ #609

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions Linked List C++
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{int info;
node*next;}*newptr,*start=NULL,*rear=NULL,*save;

node* create_node(int);
void ins_beg(node*);
void ins_end(node*);
void del_beg();
void disp(node*);

void main()
{system("cls");
int choice=-1,data;

while(choice!='5')
{cout<<"Enter operation to be performed on data structure: \n";
cout<<"1.Insert at beginning(LIFO)\n"<<"2.Insert at end(FIFO)\n"<<"3.Delete from beginning\n"<<"4.Display Data Structure\n"<<"5.Exit"<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"Insert information:\n";
cin>>data;
newptr=create_node(data);
if(newptr==NULL)
{cout<<"Could not create node! Aborting!";
exit(0);}
else
{ins_beg(newptr);}
break;
case 2:
cout<<"Insert information:\n";
cin>>data;
newptr=create_node(data);
if(newptr==NULL)
{cout<<"Could not create node!Aborting!";
exit(0);}
else
{ins_end(newptr);}
break;
case 3:
del_beg();
break;
case 4:
cout<<"Displaying from Start:\n";
disp(start);
break;
case 5:
system("pause");
exit(0);
};
};
getch();
}
node*create_node(int inf)
{node*ptr;
ptr=new node;
ptr->info=inf;
ptr->next=NULL;
return ptr;
}
void ins_beg(node*ptr)
{
if(start==NULL)
{
start=ptr;
}
else
{save=start;
start=ptr;
start->next=save;
}
}
void ins_end(node*ptr)
{
if(start==NULL)
{start=rear=ptr;}
else
{rear->next=ptr;
rear=ptr;
}
}
void del_beg()
{if(start==NULL)
{cout<<"Underflow!Aborting!";
system("pause");
exit(0);}
else
{node*ptr=start;
start=start->next;
delete ptr;
}}
void disp(node*ptr)
{while(ptr!=NULL)
{cout<<ptr->info<<"->";
ptr=ptr->next;
}
cout<<"!!!\n";
}