Advertisement
apl-mhd

Linked_list_In_a_position

Feb 24th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. int count = 0;
  4. using namespace std;
  5. struct node{
  6.        
  7.     int data;
  8.     struct node *next;
  9.    
  10. };
  11.  
  12. struct node *head;
  13.  
  14. void Insert(int x){
  15.     struct node *temp =new node();
  16.    
  17.     temp->data = x;
  18.     temp->next = head;
  19.     head = temp;
  20.    
  21. }
  22.  
  23. void Print(){
  24.         struct node *temp =new node();
  25.     temp = head;
  26.    
  27.     while(temp !=NULL){
  28.        
  29.         printf(" %d ",temp->data);
  30.         temp=temp->next;
  31.     }
  32.    
  33.     printf("\n");
  34.    
  35. }
  36.  
  37. void search(int x, int replace){
  38.     struct node *temp =new node();
  39.     //struct node *add =new node();
  40.    
  41.     //temp = head;
  42.    
  43.     if(head->data == x){
  44.         temp->data=replace;
  45.         temp->next=head;
  46.         head = temp;
  47.         //add->next =
  48.  
  49.         return;
  50.         }
  51.     if(head->next->next->data == 20){
  52.         temp = head->next->next;
  53.         temp->data = replace;
  54.        
  55.         printf("found\n");
  56.    
  57.     }
  58. }
  59.  
  60. int main(int argc, char **argv)
  61. {
  62.     head = NULL;
  63.    
  64.         Insert(10);
  65.         Insert(20);
  66.         Insert(30);
  67.         Insert(40);
  68.         search(30,100);
  69.         //search(100,1);
  70.         Print();
  71.    
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement