What's New-Given Below
technicalsymposium
technicalsymposium
technicalsymposium

College Lab Codings/Project Codings-Download


DataStructure-Program that implements deque using an array.

#include <stdio.h>
#include <conio.h>
#define MAX 10
void addqatbeg ( int *, int, int *, int * ) ;
void addqatend ( int *, int, int *, int * ) ;
int delqatbeg ( int *, int *, int * ) ;
int delqatend ( int *, int *, int * ) ;
void display ( int * ) ;
int count ( int * ) ;
void main( )
{
int arr[MAX] ;
int front, rear, i, n ;
clrscr( ) ;
/* initialises data members */
front = rear = -1 ;
for ( i = 0 ; i < MAX ; i++ )
arr[i] = 0 ;
addqatend ( arr, 17, &front, &rear ) ;
addqatbeg ( arr, 10, &front, &rear ) ;
addqatend ( arr, 8, &front, &rear ) ;
addqatbeg ( arr, -9, &front, &rear ) ;
addqatend ( arr, 13, &front, &rear ) ;
addqatbeg ( arr, 28, &front, &rear ) ;
addqatend ( arr, 14, &front, &rear ) ;
addqatbeg ( arr, 5, &front, &rear ) ;
addqatend ( arr, 25, &front, &rear ) ;
addqatbeg ( arr, 6, &front, &rear ) ;
addqatend ( arr, 21, &front, &rear ) ;
addqatbeg ( arr, 11, &front, &rear ) ;
printf ( "\nElements in a deque: " ) ;
display ( arr ) ;
n = count ( arr ) ;
printf ( "\nTotal number of elements in deque: %d", n ) ;
i = delqatbeg ( arr, &front, &rear ) ;
printf ( "\nItem extracted: %d", i ) ;
i = delqatbeg ( arr, &front, &rear ) ;
printf ( "\nItem extracted:%d", i ) ;
i = delqatbeg ( arr, &front, &rear ) ;
printf ( "\nItem extracted:%d", i ) ;
i = delqatbeg ( arr, &front, &rear ) ;
printf ( "\nItem extracted: %d", i ) ;
printf ( "\nElements in a deque after deletion: " ) ;
display ( arr ) ;
addqatend ( arr, 16, &front, &rear ) ;
addqatend ( arr, 7, &front, &rear ) ;
printf ( "\nElements in a deque after addition: " ) ;
display ( arr ) ;
i = delqatend ( arr, &front, &rear ) ;
printf ( "\nItem extracted: %d", i ) ;
i = delqatend ( arr, &front, &rear ) ;
printf ( "\nItem extracted: %d", i ) ;
printf ( "\nElements in a deque after deletion: " ) ;
display ( arr ) ;
n = count ( arr ) ;
printf ( "\nTotal number of elements in deque: %d", n ) ;
getch( ) ;
}
/* adds an element at the beginning of a deque */
void addqatbeg ( int *arr, int item, int *pfront, int *prear )
{
int i, k, c ;
if ( *pfront == 0 && *prear == MAX - 1 )
{
printf ( "\nDeque is full.\n" ) ;
return ;
}
if ( *pfront == -1 )
{
*pfront = *prear = 0 ;
arr[*pfront] = item ;
return ;
}
if ( *prear != MAX - 1 )
{
c = count ( arr ) ;
k = *prear + 1 ;
for ( i = 1 ; i <= c ; i++ )
{
arr[k] = arr[k - 1] ;
k-- ;
}
arr[k] = item ;
*pfront = k ;
( *prear )++ ;
}
else
{
( *pfront )-- ;
arr[*pfront] = item ;
}
}
/* adds an element at the end of a deque */
void addqatend ( int *arr, int item, int *pfront, int *prear )
{
int i, k ;
if ( *pfront == 0 && *prear == MAX - 1 )
{
printf ( "\nDeque is full.\n" ) ;
return ;
}
if ( *pfront == -1 )
{
*prear = *pfront = 0 ;
arr[*prear] = item ;
return ;
}
if ( *prear == MAX - 1 )
{
k = *pfront - 1 ;
for ( i = *pfront - 1 ; i < *prear ; i++ )
{
k = i ;
if ( k == MAX - 1 )
arr[k] = 0 ;
else
arr[k] = arr[i + 1] ;
}
( *prear )-- ;
( *pfront )-- ;
}
( *prear )++ ;
arr[*prear] = item ;
}
/* removes an element from the *pfront end of deque */
int delqatbeg ( int *arr, int *pfront, int *prear )
{
int item ;
if ( *pfront == -1 )
{
printf ( "\nDeque is empty.\n" ) ;
return 0 ;
}
item = arr[*pfront] ;
arr[*pfront] = 0 ;
if ( *pfront == *prear )
*pfront = *prear = -1 ;
else
( *pfront )++ ;
return item ;
}
/* removes an element from the *prear end of the deque */
int delqatend ( int *arr, int *pfront, int *prear )
{
int item ;
if ( *pfront == -1 )
{
printf ( "\nDeque is empty.\n" ) ;
return 0 ;
}
item = arr[*prear] ;
arr[*prear] = 0 ;
( *prear )-- ;
if ( *prear == -1 )
*pfront = -1 ;
return item ;
}
/* displays elements of a deque */
void display ( int *arr )
{
int i ;
printf ( "\n front->" ) ;
for ( i = 0 ; i < MAX ; i++ )
printf ( "\t%d", arr[i] ) ;
printf ( " <-rear" ) ;
}
/* counts the total number of elements in deque */
int count ( int *arr )
{
int c = 0, i ;
for ( i = 0 ; i < MAX ; i++ )
{
if ( arr[i] != 0 )
c++ ;
}
return c ;
}

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