Jacob_Thomas

DLL

Aug 29th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. void del_mid(node *h);
  4. typedef struct Node
  5. {
  6.     int info;
  7.     struct Node *pre, *next;
  8. }node;
  9.  
  10. void del_mid(struct node *h)
  11. {
  12.     node *ptr; int count=0, count2=0;
  13.     ptr=h;
  14.     do
  15.     {
  16.         count++;
  17.         ptr=ptr->next;
  18.     }
  19.     while(ptr->next!=NULL);
  20.     ptr=h;
  21.     while(count2!=(count/2))
  22.     {
  23.         ptr=ptr->next;
  24.     }
  25.    
  26.     ptr->next=ptr->next->next;
  27.     ptr->next->pre=ptr;
  28.     do
  29.     {
  30.         printf("%d ", h->info);
  31.     }
  32.     while(ptr->next!=NULL);
  33. }
  34. int main() {
  35.    node *ptr, *h; int i;
  36.    h=(node*)malloc(sizeof(node));
  37.    h->pre=NULL;
  38.    ptr=h;
  39.    for(i=0;i<5;i++)
  40.    {
  41.        ptr->next=(node*)malloc(sizeof(node));
  42.        scanf("%d", &(ptr->info));
  43.        ptr->next->pre=ptr;
  44.    }
  45.    del_mid(node *h);
  46.    return(0);
  47.    
  48. }
Add Comment
Please, Sign In to add comment