Posts

Showing posts from April, 2019

Finding the K th node from the end using Double Linked List

Link for the program in Github is below. #include<stdio.h> #include<stdlib.h> struct node{     int data;     struct node *pdr;     struct node *ndr; }; struct node *start=NULL,*ptr,*nnode=NULL,*ptr2,*ptr3,ptr4; void main() {     int x,n,k;     printf("Enter the data and if entering (-ve) integers it stop taking inputs(data) : \n");     scanf("%d",&x);     while(x>=0)     {         nnode=(struct node*)malloc(sizeof(struct node));         if(start==NULL)         {             nnode->data=x;             nnode->pdr=NULL;             nnode->ndr=NULL;             start=nnode;         }         else         {             ptr=start;             while(ptr->ndr)             {                 ptr=ptr->ndr;             }             ptr->ndr=nnode;             nnode->data=x;             nnode->ndr=NULL;             nnode->pdr=ptr;         }         printf("Enter the data :\n");