Doubly Linked List - DS TUTORIAL - onwnxcvnne
Headlines News :
Home » , , » Doubly Linked List - DS TUTORIAL

Doubly Linked List - DS TUTORIAL

Written By jomon on Monday 16 April 2012 | 09:03

demonstrate how to implement doubly linked list.

Code:

# include <stdio.h>
# include <stdlib.h>
struct dnode
{

int
data;
struct
dnode *prev, *next;
};


struct
dnode *insert(struct dnode *p , struct dnode **q, int n)
{

struct
dnode *temp;

if
(p==NULL)
{

p=(struct dnode *)malloc(sizeof(struct dnode));
if
(p==NULL)
{

printf("Error Occurred\n");
exit(0);
}

p->data = n;
p-> prev = p->next =NULL;
*
q =p;
}

else

{

temp = (struct dnode *)malloc(sizeof(struct dnode));

if
(temp == NULL)
{

printf("Error Occurred\n");
exit(0);
}

temp->data = n;
temp->prev = (*q);
temp->next = NULL;
(*
q)->next = temp;
(*
q) = temp;
}

return
(p);
}


void
printnode( struct dnode *p )
{

printf("All data of created list is\n");
while
(p!= NULL)
{

printf("%d\t",p-> data);
p = p->next;
}
}


void
main()
{

int
n;
int
x;
struct
dnode *start = NULL ;
struct
dnode *end = NULL;
printf("Enter the number of nodes to be created \n");
scanf("%d",&n);
while
( n-- > 0 )
{

printf( "Enter the data values for each node\n");
scanf("%d",&x);
start = insert ( start , &end,x );
}

printnode( start );
}

Output:




Previous - Singly Linked List

     Next - Circular Linked List

 Data Structure Tutorial 

1.  Introduction to Data Structures
2.  Pointer in C 
3.  Pointer and Structure in C
4.  Linear and Non-Linear Data Structure in C
5.  Array Implementation in C
6.  Sum of array element in C
7.  Addition of two arrays element in C
8.  Inverse of an array in C
9.  Merge of two arrays in C 
10.Overview of Linked List
11.Singly Linked List
12.Doubly Linked List
13.Circular Linked List
14.Count number of nodes
15.Split a list into two equal size list
16.Merge two list into a single list
17.Stack
18.Push and Pop operation of stack.
19.Push and Pop operation of stack using linked list.
20.Queue implementation using array.
21.Queue implementation using linked list.
22.Circular queue implementation using array.
23.Tree data structure
24.Representing Graph using adjacency list & perform DFS & BFS
Share this article :

0 comments:

Speak up your mind

Tell us what you're thinking... !

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. onwnxcvnne - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger