Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct node
- {
- int data;
- int phone;
- char name [20];
- struct node *next;
- };
- struct node *head=NULL,*temp,*p,*store;
- void display()
- {
- temp=head;
- cout<<endl;
- while(temp!=NULL)
- {
- cout<<temp->data<<endl;
- cout<<temp->phone<<endl;
- cout<<temp->name<<endl;
- temp=temp->next;
- }
- }
- void findata(int d)
- {
- temp=head;
- int count=0;
- cout<<"Give new node information: "<<endl;
- p=(struct node*) malloc (sizeof(struct node));
- store =(struct node*) malloc (sizeof(struct node));
- cin>>p->data;
- cin>>p->phone;
- cin>>p->name;
- p->next=NULL;
- while(temp->data!=d && temp->next!=NULL)
- {
- count++;
- temp=temp->next;
- }
- if(temp->data==d)
- {
- cout<<endl<<"**Data found at position: "<<count+1 <<endl;
- store->next=temp->next;
- temp->next=p;
- p->next=store->next;
- }
- else
- {
- cout<<endl<<"**Data was not found: "<<endl;
- }
- }
- void edit(int ha)
- {
- temp=head;
- int count=0;
- while(temp->data!=ha&& temp->next!=NULL)
- {
- count++;
- temp=temp->next;
- }
- if(temp->data==ha)
- {
- cout<<endl<<"**Data found at position: "<<count+1 <<endl;
- cin>>temp->data;
- cin>>temp->phone;
- cin>>temp->name;
- }
- else
- {
- cout<<endl<<"**Data was not found: "<<endl;
- }
- }
- void delete_data(int g)
- {
- struct node *l,*m;
- l=head;
- m=head->next;
- if(l->data==g)
- {
- head=m;
- delete(l);
- }
- else
- {
- while(m->data!=g)
- {
- m=m->next;
- l=l->next;
- }
- if(m->next==NULL)
- {
- l->next=NULL;
- delete(m);
- }
- else
- {
- l->next=m->next;
- delete(m);
- }
- }
- }
- int main()
- {
- int n,i,x;
- cout<<"Enter how many link list u want:"<<endl;
- cin>>n;
- cout<<"Where u want to insert:"<<endl<<endl;
- cout<<"For inserting first press 1:"<<endl;
- cout<<"For inserting in last press 2:"<<endl;
- cin>>x;
- for(i=1; i<=n; i++)
- {
- struct node *newnode,*s;
- newnode=(struct node*) malloc (sizeof(struct node));
- cout<<"Enter information: "<<endl;
- cin>>newnode->data;
- cin>>newnode->phone;
- cin>>newnode->name;
- newnode->next=NULL;
- if(x==1)
- {
- if(head==NULL)
- {
- head=newnode;
- }
- else
- {
- newnode->next=head;
- head=newnode;
- }
- }
- if(x==2)
- {
- if(head==NULL)
- {
- head=newnode;
- s=head;
- }
- else
- {
- s->next=newnode;
- s=newnode;
- }
- }
- }
- display();
- cout<<"Enter which data your searching for:"<<endl;
- int d;
- cin>>d;
- findata(d);
- display();
- cout<<"Enter a data of a note which u want to delete:"<<endl;
- int g;
- cin>>g;
- delete_data(g);
- display();
- int ha;
- cout<<"Enter where you want to edit"<<endl;
- cin>>ha;
- edit(ha);
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement