What's New-Given Below
technicalsymposium
technicalsymposium
technicalsymposium

College Lab Codings/Project Codings-Download


DataStructure-Program to maintain a doubly linked list.

#include <stdio.h>
#include <conio.h>
#include <alloc.h>
/* structure representing a node of the doubly linked list */
struct dnode
{
struct dnode *prev ;
int data ;
struct dnode * next ;
} ;
void d_append ( struct dnode **, int ) ;
void d_addatbeg ( struct dnode **, int ) ;
void d_addafter ( struct dnode *, int , int ) ;
void d_display ( struct dnode * ) ;
int d_count ( struct dnode * ) ;
void d_delete ( struct dnode **, int ) ;
void main( )
{
struct dnode *p ;
p = NULL ; /* empty doubly linked list */
d_append ( &p , 11 ) ;
d_append ( &p , 2 ) ;
d_append ( &p , 14 ) ;
d_append ( &p , 17 ) ;
d_append ( &p , 99 ) ;
clrscr( ) ;
d_display ( p ) ;
printf ( "\nNo. of elements in the DLL = %d\n", d_count ( p ) ) ;
d_addatbeg ( &p, 33 ) ;
d_addatbeg ( &p, 55 ) ;
d_display ( p ) ;
printf ( "\nNo. of elements in the DLL = %d\n", d_count ( p ) ) ;
d_addafter ( p, 4, 66 ) ;
d_addafter ( p, 2, 96 ) ;
d_display ( p ) ;
printf ( "\nNo. of elements in the DLL = %d\n", d_count ( p ) ) ;
d_delete ( &p, 55 ) ;
d_delete ( &p, 2 ) ;
d_delete ( &p, 99 ) ;
d_display ( p ) ;
printf ( "\nNo. of elements in the DLL = %d\n", d_count ( p ) ) ;
}
/* adds a new node at the end of the doubly linked list */
void d_append ( struct dnode **s, int num )
{
struct dnode *r, *q = *s ;
/* if the linked list is empty */
if ( *s == NULL )
{
/*create a new node */
*s = malloc ( sizeof ( struct dnode ) ) ;
( *s ) -> prev = NULL ;
( *s ) -> data = num ;
( *s ) -> next = NULL ;
}
else
{
/* traverse the linked list till the last node is reached */
while ( q -> next != NULL )
q = q -> next ;
/* add a new node at the end */
r = malloc ( sizeof ( struct dnode ) ) ;
r -> data = num ;
r -> next = NULL ;
r -> prev = q ;
q -> next = r ;
}
}
/* adds a new node at the begining of the linked list */
void d_addatbeg ( struct dnode **s, int num )
{
struct dnode *q ;
/* create a new node */
q = malloc ( sizeof ( struct dnode ) ) ;
/* assign data and pointer to the new node */
q -> prev = NULL ;
q -> data = num ;
q -> next = *s ;
/* make new node the head node */
( *s ) -> prev = q ;
*s = q ;
}
/* adds a new node after the specified number of nodes */
void d_addafter ( struct dnode *q, int loc, int num )
{
struct dnode *temp ;
int i ;
/* skip to desired portion */
for ( i = 0 ; i < loc ; i++ )
{
q = q -> next ;
/* if end of linked list is encountered */
if ( q == NULL )
{ printf ( "\nThere are less than %d elements", loc );
return ;
}
}
/* insert new node */
q = q -> prev ;
temp = malloc ( sizeof ( struct dnode ) ) ;
temp -> data = num ;
temp -> prev = q ;
temp -> next = q -> next ;
temp -> next -> prev = temp ;
q -> next = temp ;
}
/* displays the contents of the linked list */
void d_display ( struct dnode *q )
{
printf ( "\n" ) ;
/* traverse the entire linked list */
while ( q != NULL )
{
printf ( "%2d\t", q -> data ) ;
q = q -> next ;
}
}
/* counts the number of nodes present in the linked list */
int d_count ( struct dnode * q )
{
int c = 0 ;
/* traverse the entire linked list */
while ( q != NULL )
{
q = q -> next ;
c++ ;
}
return c ;
}
/* deletes the specified node from the doubly linked list */
void d_delete ( struct dnode **s, int num )
{
struct dnode *q = *s ;
/* traverse the entire linked list */
while ( q != NULL )
{
/* if node to be deleted is found */
if ( q -> data == num )
{
/* if node to be deleted is the first node */
if ( q == *s )
{
*s = ( *s ) -> next ;
( *s ) -> prev = NULL ;
}
else
{
/* if node to be deleted is the last node */
if ( q -> next == NULL )
q -> prev -> next = NULL ;
else
/* if node to be deleted is any intermediate node */
{
q -> prev -> next = q -> next ;
q -> next -> prev = q -> prev ;
}
free ( q ) ;
}
return ; /* return back after deletion */
}
q = q -> next ; /* go to next node */
}
printf ( "\n%d not found.", num ) ;
}

technicalsymposium

Technicalsymposium.com-A Complete Website for Engineering Students & Engineering Faculties.All Useful Links & Contents Given Below

technicalsymposium

Free Email Alerts
Get free email alerts-Fresher’s Jobs/Conference/Symposium/Exams Alerts-Click here to Subscribe.

Free Event Publishing
Publish your college technical symposium/free events in our website & Attract more targeted audience- Click here to Get

Conference/Symposium
All engineering colleges /Premier Institutions (IIT,IISC,NIT,etc.,) Conferences/Workshop details-Click here to Get

Fresher’s Jobs/Scholarships Details
Freshers Software Jobs/Government Jobs and Student Internships/Scholarships Details- Click here to Get

Placement Papers
All Software Companies previous placement papers/Govt Competitive exam previous papers/Tech Materials free download-Click her to get.

Lab Programs/Lab Manuals
All Branches of Lab Programs/Lab Manuals for all branches of Engineering-Click here to Get

University Previous Question Papers
Anna university/All leading universities previous question papers year wise and Semester wise- Click here to Get

GATE Question Papers
GATE Previous Question Papers –All Branches by year wise-Click here to Get

Indian Engineering Services (IES) Question Papers
IES Previous Question Papers –All Branches by year wise-Click here to Get

Anna University Syllabus
Anna University all branches syllabues free download for all B.E(All Branches)/B.Tech(All Branches)/M.E/M.Tech/MCA/MBA- Click here to Get

GATE/ All Entrance Exam Syllabus
GATE/ All Leading Entrance Exam Syllabus free download-Click here to Get

Competitive Exam Syllabuses
Bank/Railway/SSC,all kind of Competitive Exam syllabuses free Download-Click here to get

Civil Engineering Lecture Notes
Civil engineering lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Electronics & Communication Engineering (ECE) Lecture Notes
Electronics & Communication Engineering (ECE) by semester wise and Lab Programs/Manuals-Click here to get

Electronics & Electronics Engineering (EEE) Lecture Notes
Electronics & Electronics Engineering (EEE) lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Mechanical Engineering (MECH) Lecture Notes
Mechanical Engineering (MECH) lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Computer Science Engineering (CSE) Lecture Notes
Computer Science Engineering (CSE) lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Information Technology Lecture Notes
Information Technology lecture notes by semester wise and Lab Programs/Manuals-Click here to get

MCA Lecture Notes
MCA lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Automobile Engineering Lecture Notes
Automobile Engineering lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Aeronautical Engineering Lecture Notes
Aeronautical Engineering lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Bio-Medical Engineering Lecture Notes
Bio-Medical Engineering lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Bio-Technology Lecture Notes
Bio-Technology lecture notes by semester wise and Lab Programs/Manuals-Click here to get

MBA Lecture Notes
MBA lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com