Advertisement
apl-mhd

bappy sir 2

Mar 17th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. #include <cstring>
  2. #include <iostream>
  3. #include <cstdio>
  4. using namespace std;
  5.  
  6. struct list{
  7.  
  8.         int data;
  9.         struct list *next;
  10.         struct list *prev;
  11.  
  12. };
  13.  
  14. typedef struct list node;
  15.  
  16. node *Insert(node *head, int y,int x){
  17.  
  18.         node *temp, *temp2,*temp3, *prev, *insertData;
  19.  
  20.             temp = head;
  21.  
  22.             while(temp->next !=NULL && temp->data != x)
  23.                 temp = temp->next;
  24.  
  25.             if(temp->next == NULL){
  26.               //  printf("ork\n");
  27.                 insertData = new node();
  28.                 insertData->data = x;
  29.                 insertData->next=temp->next;
  30.                 insertData->prev= temp;
  31.                 temp->next=insertData;
  32.             }
  33.  
  34.  
  35.             printf("%d\n", insertData->next);
  36.  
  37.         return head;
  38. }
  39.  
  40.  
  41. void shw(node *head){
  42.  
  43.     if(head->next == NULL){
  44.         printf("no data found");
  45.         return;
  46.     }
  47.  
  48.     while(head->next !=NULL){
  49.  
  50.         printf("%d ", head->next->data);
  51.         head= head->next;
  52.     }
  53.     cout<<endl;
  54. }
  55. /*
  56. node *delItem(node *head, int value){
  57.  
  58.             node *temp;
  59.             temp = head->next;
  60.  
  61.         while(temp->data !=value && temp->next !=NULL)
  62.                 temp = temp->next;
  63.  
  64.  
  65.  
  66.         if(temp->data == value &&temp->next ==NULL){
  67.  
  68.             temp->prev->next = NULL;
  69.  
  70.             delete temp;
  71.            return head;
  72.         }
  73.  
  74.         else if(temp->data == value){
  75.  
  76.                 temp->prev->next = temp->next;
  77.                 temp->next->prev = temp->prev;
  78.  
  79.                 printf("Node with key value %d is DELETED\n", value);
  80.  
  81.                 delete temp;
  82.  
  83.             return head;
  84.  
  85.         }
  86.  
  87.         else{
  88.  
  89.             printf("delete not possible \n");
  90.             return head;
  91.         }
  92. }
  93.  
  94. void searchData(node *head, int value){
  95.  
  96.         node *temp;
  97.         temp = head->next;
  98.         while(temp->next !=NULL && temp->data == value)
  99.             temp  = temp->next;
  100.         if(temp->data = value)
  101.             printf("Node with key value %d is FOUNDED\n",temp->data);
  102.         else
  103.         {
  104.              printf("Node found\n",temp->data);
  105.         }
  106. }
  107. */
  108.  
  109. int main(int argc, char **argv)
  110. {
  111.  
  112.  
  113.     int flag=1;
  114.     int y, x,del, value;
  115.     char function[20];
  116.  
  117.     node *head;
  118.  
  119.     head = new node();
  120.     head->next=NULL;
  121.     head->prev=NULL;
  122.  
  123.  
  124.     while(flag){
  125.  
  126.         scanf("%s",function);
  127.  
  128.         if(strcmp(function, "ins")==0){
  129.  
  130.  
  131.                 scanf("%d%d", &y,&x);
  132.  
  133.                  head= Insert(head,y,x);
  134.  
  135.  
  136.             }
  137.  
  138.  
  139.  
  140.         if(strcmp(function, "del")==0){
  141.  
  142.             cin>>del;
  143.            // head = delItem(head, del);
  144.  
  145.             }
  146.  
  147.         if(strcmp(function, "sch")==0){
  148.  
  149.             cin>>value;
  150.            // searchData(head,value);
  151.  
  152.         }
  153.  
  154.          if(strcmp(function, "shw")==0){
  155.  
  156.                 shw(head);
  157.  
  158.  
  159.             }
  160.  
  161.  
  162.         if(strcmp(function, "ext")==0){
  163.  
  164.             flag =0;
  165.  
  166.             }
  167.  
  168.  
  169.         }
  170.  
  171.     return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement