Advertisement
apl-mhd

Linked_List_Delete_ In_a_position

Mar 3rd, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. using namespace std;
  6.  
  7. struct list{
  8.  
  9.     int data;
  10.     struct list *next;
  11.    
  12. };
  13.  
  14. typedef list node;
  15.  
  16. node * head, *a;
  17.  
  18.  
  19. void Print(){
  20.    
  21.    
  22.    
  23. }
  24.  
  25. int main(int argc, char **argv)
  26. {
  27.     int remove;
  28.     node *temp, *prev;
  29.    
  30.     head = new node();
  31.    
  32.     head->data=0;
  33.     temp = head;
  34.    
  35.     for(int i=1; i<10; i++){
  36.        
  37.         temp->next = new node();
  38.         temp->next->data =i;
  39.         temp->next->next=NULL;
  40.         temp = temp->next;
  41. }
  42.    
  43.    
  44.         temp = head;
  45.  
  46.     while(temp !=NULL){
  47.        
  48.         printf("%d\n", temp->data);
  49.         temp = temp->next;
  50.        
  51.     }
  52.    
  53.    
  54.     temp = head;
  55.  
  56.     cin>>remove;
  57.     while(temp->data != remove){
  58.    
  59.        
  60.         prev = temp;
  61.        
  62.         temp = temp->next;
  63.    
  64. }
  65.  
  66.     printf("\n----%d------\n", prev->data);
  67.    
  68.     prev->next = temp->next;
  69.    
  70.     delete temp;
  71.    
  72.     temp = head;
  73. cout<<"--"<<endl;
  74.  
  75.    
  76.  
  77.     while(temp !=NULL){
  78.        
  79.         printf("%d\n", temp->data);
  80.         temp = temp->next;
  81.        
  82.     }
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement