dsdeep

Q-1

Oct 18th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. void addMid(struct Node *list,int d){
  2. int c=0;
  3. struct Node *tmplist=list;
  4. while(tmplist){
  5.     c++;
  6.     tmplist=tmplist->link;
  7. }
  8. int i=1;
  9. while(list){
  10.     if(i==((c%2)==0?c/2:(c/2)+1)){
  11.         struct Node *tmp=(struct Node*)malloc(sizeof(struct Node));
  12.         tmp->link=list->link;
  13.         tmp->info=list->info;
  14.     list->info=d;
  15.         list->link=tmp;
  16.         return;
  17.     }
  18.     i++;
  19.     list=list->link;
  20. }
  21. }
  22. void search(struct Node *list,int d){
  23.     while(list){
  24.         if(list->info==d){
  25.             printf("%d Found\n",d);
  26.             return;
  27.         }
  28.         list=list->link;
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment