#include
using namespace std;
void main_menu();
void insertion (int n);
void del (int x);
void search();
struct Node // node is naame it could me anything
{
int data;
Node * next;
};
Node *start,*current,*temp='\0';
int Tayyaba=0;
int main ()
{
main_menu();
return 0;
}
void main_menu()
{
int w=1;
while(w==1)
{
char choice;
cout<<"-- IMPLIMENTATION OF Linked list --"< cout<<"\t\t\t==========>> 1: Insertion "< cout<<"\t\t\t==========>> 2: Delete "< cout<<"\t\t\t==========>> 3: View "< cout<<"\t\t\t==========>> 4: Search "< cout<<"\t\t\t==========>> 5: Exit "<
cout<<"\n\n\t\t\t Select option wisely"< cin>>choice;
switch(choice)
{
case '1':
system("cls");
int n;
cout<<"enter value you want to insert"< cin>>n;
insertion(n);
break;
case '2':
system("cls");
break;
case '3':
system("cls");
//print();
break;
case '4':
system("cls");
break;
case '5':
system("cls");
w++;
break;
default :
system("cls");
}
}
}
void insertion (int n)
{
if(start=='\0')
{
start =new Node;
start->data=n;
start->next='\0';
}
else
{
current=start;
while (current->next!='\0')
{
current=current->next;
temp=new Node;
temp->data =10;
temp->next='\0';
current=current->next;
}
}
}
void del ()
{
int val=0,n=0;
//deletion from start//
if (start == NULL)
cout << "There is no linked list node to pop.\n";
else{
temp = start;
cout << "enter the value you want to delete :";
cin >> n;
while (temp->next != NULL){
if (temp->data == n){
cout << "temp data =" << temp->data << " n =" << n << endl;
current = start;
break;
}
else
temp = temp->next;
}
while (current->next != NULL){
if (current->next == temp){
cout << "current next=" << current->next << " temp =" << temp << endl;
current->next = temp->next;
temp->next = NULL;
delete temp;
}
else
current = current->next;
}
}
// deletion from star with only one node //
if (start->next == NULL && start->data == n){
start = NULL;
}
//deletion from start//
if (start->data == n){
temp = start;
start = start->next;
temp->next = NULL;
delete temp;
}
// deletion from end//
temp = start;
while (temp->next != NULL)
temp = temp->next;
if (temp->data==n)
{
cout << "temp data =" << temp->data << " n =" << n<< endl;
current = start;
while (current->next != NULL){
if (current->next == temp){
current->next = NULL;
cout << "this value will del =" << temp->data << endl;
delete temp;
}
else
current = current->next;
}
}
}
void search()
{
int x;
cout<<"enter value you want to search "< cin>>x;
while(current->next !='\0')
if(x==current->data)
{
cout<<"Search is found"<data;
}
else
{
cout<<"result not found"< }
}
using namespace std;
void main_menu();
void insertion (int n);
void del (int x);
void search();
struct Node // node is naame it could me anything
{
int data;
Node * next;
};
Node *start,*current,*temp='\0';
int Tayyaba=0;
int main ()
{
main_menu();
return 0;
}
void main_menu()
{
int w=1;
while(w==1)
{
char choice;
cout<<"-- IMPLIMENTATION OF Linked list --"<
cout<<"\n\n\t\t\t Select option wisely"<
switch(choice)
{
case '1':
system("cls");
int n;
cout<<"enter value you want to insert"<
insertion(n);
break;
case '2':
system("cls");
break;
case '3':
system("cls");
//print();
break;
case '4':
system("cls");
break;
case '5':
system("cls");
w++;
break;
default :
system("cls");
}
}
}
void insertion (int n)
{
if(start=='\0')
{
start =new Node;
start->data=n;
start->next='\0';
}
else
{
current=start;
while (current->next!='\0')
{
current=current->next;
temp=new Node;
temp->data =10;
temp->next='\0';
current=current->next;
}
}
}
void del ()
{
int val=0,n=0;
//deletion from start//
if (start == NULL)
cout << "There is no linked list node to pop.\n";
else{
temp = start;
cout << "enter the value you want to delete :";
cin >> n;
while (temp->next != NULL){
if (temp->data == n){
cout << "temp data =" << temp->data << " n =" << n << endl;
current = start;
break;
}
else
temp = temp->next;
}
while (current->next != NULL){
if (current->next == temp){
cout << "current next=" << current->next << " temp =" << temp << endl;
current->next = temp->next;
temp->next = NULL;
delete temp;
}
else
current = current->next;
}
}
// deletion from star with only one node //
if (start->next == NULL && start->data == n){
start = NULL;
}
//deletion from start//
if (start->data == n){
temp = start;
start = start->next;
temp->next = NULL;
delete temp;
}
// deletion from end//
temp = start;
while (temp->next != NULL)
temp = temp->next;
if (temp->data==n)
{
cout << "temp data =" << temp->data << " n =" << n<< endl;
current = start;
while (current->next != NULL){
if (current->next == temp){
current->next = NULL;
cout << "this value will del =" << temp->data << endl;
delete temp;
}
else
current = current->next;
}
}
}
void search()
{
int x;
cout<<"enter value you want to search "<
while(current->next !='\0')
if(x==current->data)
{
cout<<"Search is found"<
}
else
{
cout<<"result not found"<
}
No comments:
Post a Comment