Created
March 9, 2019 16:20
-
-
Save luk0y/c24d7b3283c38a8d0b223e9189860bfa to your computer and use it in GitHub Desktop.
Creation of a double linked list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//By luk0y | |
#include <stdio.h> | |
#include <stdlib.h> | |
struct node { | |
int data; | |
struct node *prev; | |
struct node *post; | |
}; | |
void main() | |
{ | |
int x,y; | |
int i,j,Temp; | |
struct node *start=NULL,*new_node,*ptr,*pttr; | |
printf("Enter number of nodes you want to enter : ");//Don't use 0 for giving the number of nodes | |
scanf("%d",&x); | |
printf("Enter the data :\n"); | |
while(x!=0) | |
{ | |
scanf("%d",&y); | |
new_node=(struct node*)malloc(sizeof(struct node)); | |
if(new_node==NULL) | |
{ | |
printf("No space"); | |
} | |
else | |
{ | |
if(start==NULL) | |
{ | |
start=new_node; | |
new_node->data=y; | |
new_node->prev=NULL; | |
new_node->post=NULL; | |
} | |
else | |
{ | |
ptr=start; | |
while(ptr->post!=NULL) | |
{ | |
ptr=ptr->post; | |
} | |
ptr->post=new_node; | |
new_node->data=y; | |
ptr->post->prev=ptr; | |
new_node->post=NULL; | |
} | |
} | |
x--; | |
} | |
printf("\nDouble Linked list : \n"); | |
new_node=start; | |
while(new_node!=NULL) | |
{ | |
printf("%d\n",new_node->data); | |
new_node=new_node->post; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment