URI:
   DIR Return Create A Forum - Home
       ---------------------------------------------------------
       Class Discussion
  HTML https://srm.createaforum.com
       ---------------------------------------------------------
       *****************************************************
   DIR Return to: Data Structure
       *****************************************************
       #Post#: 7--------------------------------------------------
       Node Data Delete (Data Structure)
   DIR By: prannyll
       Date: April 18, 2019, 8:32 am
       ---------------------------------------------------------
       #include<stdio.h>
       #include<stdlib.h>
       #include<conio.h>
       void vnode(); void dnode();
       int count = 0, ch, n = 5;
       typedef struct node{
       int data;
       struct node *next;
       }t;
       t* temp;
       t* head;
       t* ptr;
       t* ptr2;
       void main()
       {
       int i;
       clrscr();
       for(i = 1; i <= n; i++)
       {
       t* ptr = (t*)malloc(sizeof(t*));
       t* ptr2 = (t*)malloc(sizeof(t*));
       ptr->data = i;
       ptr->next = ptr2;
       if(i == n)
       ptr->next = NULL;
       free(ptr2);
       count++;
       if(count == 1)
       head = ptr;
       printf("\n(%d) MAIN: %u  DATA: %d  NEXT: %u",i, ptr,
       ptr->data, ptr->next);
       }
       printf("\n------------ %d NODES --------------\n", count);
       dnode();
       getch();
       }
       //DELETE NODE FUNCTION
       void dnode()
       {
       int i;
       printf("\nWhich node you want to remove?\n>>");
       scanf("%d", &ch);
       temp = head;
       for(i = 1; i<=ch-1; i++)
       {
       if(i == ch-1 && ch == n)
       ptr2 = temp;
       temp = temp->next;
       }
       printf("\nDATA REMOVED! \nMAIN: %u  DATA: %d  NEXT: %u",
       temp, temp->data, temp->next);
       for(i = ch; i<=n; i++)
       {
       temp->data=(temp->next)->data;
       if(i == n-1)
       ptr = temp;
       temp = temp->next;
       ptr->next = NULL;
       }
       ptr2->next = NULL;
       count--;
       vnode();
       }
       //DISPLAY NODE FUNCTION
       void vnode()
       {
       int i;
       ptr = head;
       printf("\n___________________________________\n");
       for(i = 1; i<=count; i++)
       {
       printf("\n(%d) MAIN: %u  DATA: %d  NEXT: %u",i, ptr,
       ptr->data, ptr->next);
       ptr = ptr->next;
       }
       printf("\n------------ %d NODES --------------\n", count);
       }
       *****************************************************
       Page 1 of 1