Linked List Graphics

45
Lovely institute of engineering and Computer application b.tech-m.tech(dual degree)- cse mini project on- implementation of doubly linked list using graphics submitted t0- submitted by- miss deepika sukhija AJAY KUMAR

Transcript of Linked List Graphics

Page 1: Linked List Graphics

Lovely institute of engineering and

Computer application

b.tech-m.tech(dual degree)- cse

mini project on- implementation of doubly linked list using graphics

submitted t0- submitted by-

miss deepika sukhija AJAY KUMAR

roll n0-rk2r13a15

regn no-11009446

Page 2: Linked List Graphics

Acknowledgment

I have created and nurtured this project for last two months. The resources like

internet, books have contributed in materializing this project. This project bears an

imprint of many people. I acknowledge the magnanimous support and guidance of

these resources in carrying out this project work. I also wish to express heartfelt

gratitude to my mam and my friends who have rendered their generous assistance.

It would be injustice if I don’t thank my friends who helped me during this project.

Contents-

1. Introduction of link list

2. Doubly link list

3. Functions of graphics

a) getcolor function

b) cleardevice function

c) getmaxcolor function

d) getmaxy function

e) setcolor function

f) putpixel function

g) Source code

4. references

Page 3: Linked List Graphics

Link list-

In computer science, a linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of a datum and a reference (in other words, a link) to the next node in the sequence; more complex variants add additional links. This structure allows for efficient insertion or removal of elements from any position in the sequence.

Doubly link list-

In computer science, a doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes. The beginning and ending nodes' previous and next links, respectively, point to some kind of terminator, typically a sentinel node or null, to facilitate traversal of the list. If there is only one sentinel node, then the list is circularly linked via the sentinel node. It can be conceptualized as two singly linked lists formed from the same data items, but in opposite sequential orders.

The two node links allow traversal of the list in either direction. While adding or removing a node in a doubly linked list requires changing more links than the same operations on a singly linked list, the operations are simpler and potentially more efficient (for nodes other than first nodes) because there is no need to keep track of the previous node during traversal or no need to traverse the list to find the previous node, so that its link can be modified.

Page 4: Linked List Graphics

Now we have to implement the doubly linked list using graphics but firstly I would like to explain about graphics and some of the graphics functions.

Functions of graphics’-

C graphics using graphics.h functions or WinBGIM (Windows 7 ) can be used to draw different shapes, display text in different fonts, change color and many more. Using functions of graphics.h in turbo c compiler you can make graphics programs, animations, projects and games.You can draw circles, lines, rectangles, bars and many other geometrical figures. You can change their colors using the available functions and fill them. Following is a list of functions of graphics.h header file. Every function is discussed with the arguments it needs, its description, possible errors while using that function and a sample c graphics program with its output.

SOME of c graphics functions-

getcolor function-

getcolor function returns the current drawing color.

Declaration : int getcolor( );

e.g. a = getcolor( ); // a is an integer variableif current drawing color is WHITE then a will be 15.

Cleardevice function-

Declaration :- void cleardevice();cleardevice function clears the screen in graphics mode and sets the current position to (0,0). Clearing the screen consists of filling the screen with current background color.

Getmaxcolor function-

Page 5: Linked List Graphics

getmaxcolor function returns maximum color value for current graphics mode and driver. Total number of colors available for current graphics mode and driver are ( getmaxcolor() + 1 ) as color numbering starts from zero.

Declaration :- int getmaxcolor( );

Getmaxy function –

getmaxy function returns the maximum Y coordinate for current graphics mode and driver.

Declaration :- int getmaxy();

Setcolor function-

Declaration :- void setcolor(int color);

In Turbo Graphics each color is assigned a number. Total 16 colors are available. Strictly speaking number of available colors depends on current graphics mode and driver.For Example :- BLACK is assigned 0, RED is assigned 4 etc. setcolor function is used to change the current drawing color.e.g. setcolor(RED) or setcolor(4) changes the current drawing color to RED. Remember that default drawing color is WHITE.

Putpixel function-

putpixel function plots a pixel at location (x, y) of specified color.

Declaration :- void putpixel(int x, int y, int color);

For example if we want to draw a GREEN color pixel at (35, 45) then we will write putpixel(35, 35, GREEN); in our c program, putpixel function can be used to draw circles, lines and ellipses using various algorithms.

Source code-

Page 6: Linked List Graphics

This program maintains a employee’s record using doubly linked list. It involves simple graphics and a login me nu where I had used file hadling to maintain a record og 3 user’s name and their password . so before running the program kindly create a text document in d:\with the name LOGIN.txt.In this just add the following data:

Ceo computer

Manager mouse

Admin hello123

i.e only 3 persons can be allowed to login with their respective password

PROGRAM-

#include<dos.h>

#include<string.h>

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

#include<alloc.h>

struct login /* Used for records of authorised login */

{ char username[30];

char password[15];

};

struct login l[3];/* as authorised users are ceo,manager and administrator */

struct employee

{ /* structure of Double linked list */

int employee_no;

char employee_name[20];

Page 7: Linked List Graphics

float grosspay;

char designation[10];

int age;

char sex[6];

struct employee *nextptr;

struct employee *previousptr;

};

typedef struct employee employee;

/*********************************FUNCTION PROTOTYPE***************************/

void border_margin(void); /* CREATING BORDER */

void printmain(void); /* PRINTING MAIN */

void new_employee(); /* APPEND FUNCTIONS */

void display(employee *); /* PRINTING THE RECORDS */

void delete_employee(); /* DELETING THE RECORDS */

void update(); /* TO MODIFY FUNCTION */

void search_employee(int); /* SEARCHING RECORDS */

void printdetail(void);

employee *getnode(int); /* FOR CREATING NEW NODES (MALLOC) */

employee *head=NULL; /* INITIALLY LINKED LIST IS EMPTY */

employee *tail=NULL;

/******************************************************************************/

int k,i,j,count=0;

char ans,choice,choice1,choice2,choice3; /* for accessing menu */

Page 8: Linked List Graphics

void main()

{ /* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int maxx, maxy,i,count=0,flag=0;

/* initialize graphics, local variables */

initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* If an error occurred as grOK means no error */

{ clrscr();

printf("Graphics Error Detected : %s\n", grapherrormsg(errorcode));

printf("Press any key to halt....");

printf("\nThank You.\t\n- Comp. Science Students.\n Batch : C-5 and C6");

printf("\n Jaypee University Of Information Technology , Waknaghat");

getch();

exit(0); /* Terminate with an error code */

}

maxx = getmaxx();

maxy = getmaxy();

setcolor(YELLOW); /* select drawing color */

setfillstyle(SOLID_FILL,BLUE); /* select fill color */

rectangle(0, 0, maxx, maxy); /* draw a border around the screen */

bar(0,0,maxx,maxy); /* for painting background blue */

settextstyle(5,0,6);

Page 9: Linked List Graphics

outtextxy(130,50,"Employee Records");

outtextxy(250,130,"Of A");

outtextxy(210,210,"Company");

settextstyle(2,0,7);

outtextxy(120,300,"A DOUBLY LINKED LIST IMPLEMENTATION");

settextstyle(2,0,4);

outtextxy(100,360,"PRESS A KEY TO CONTINUE ....");

music(3);

/********************** END OF INTRO SCREEN **************************************/

cleardevice(); /* CLEARS THE SCREEN */

settextstyle(0,0,0);

setfillstyle(SOLID_FILL,BLUE); /* select fill color */

rectangle(0, 0, maxx, maxy); /* draw a border around the screen */

bar(0,0,maxx,maxy); /* for painting background blue */

setcolor(YELLOW);

outtextxy(25,30,"ÿ");outtextxy(30,30,"Î");

outtextxy(30,25,"º");

for(i=35;i<=450;i+=5)

outtextxy(30,i,"º");

for(i=35;i<=600;i+=5)

outtextxy(i,30,"ÿ");

settextstyle(5,0,5);outtextxy(90,50,"About the Project");

char str1[70]={"Programmers : Students Of Batch C5 & C6"};

char str2[30]={"Platform : Turbo C++ IDE"};

char str3[30]={"Duration : Approx 10 Days"};

Page 10: Linked List Graphics

char str4[34]={"Instructor : Mr.Satish Chandra"};

char str5[30]={"Contacts : +919816184767"};

char str6[30]={"®® Press A Key To Continue ¯¯"};

int j=10,k=12;

settextstyle(0,0,0);

// LOGIN MENU

cleardevice();

logi: /* label to return in case access is denied */

setfillstyle(SOLID_FILL,BLUE); /* select fill color */

rectangle(0, 0, maxx, maxy); /* draw a border around the screen */

bar(0,0,maxx,maxy); /* for painting background blue */

settextstyle(5,0,5);

setcolor(YELLOW);

outtextxy(110,90,"®® Login Menu ¯¯");

settextstyle(0,0,0);

k = 155;

outtextxy(150,220,"É");

for(i=0;i<=1050;i+=4)

{ outtextxy(k,220,"ÿ");

k++;

}

outtextxy(424,220,"»");outtextxy(150,225,"º");

outtextxy(150,230,"º");outtextxy(150,235,"º");

outtextxy(150,240,"º");outtextxy(150,245,"Ì");

outtextxy(424,225,"º");outtextxy(424,230,"º");

Page 11: Linked List Graphics

outtextxy(424,235,"º");outtextxy(424,240,"º");

outtextxy(424,245,"¹");outtextxy(150,250,"º");

outtextxy(150,255,"º");outtextxy(150,260,"º");

outtextxy(150,265,"È");outtextxy(424,250,"º");

outtextxy(424,255,"º");outtextxy(424,260,"º");

outtextxy(424,265,"¼");outtextxy(160,235,"USERNAME : ");

outtextxy(160,255,"PASSWORD : ");

k=155;

char str7[15],str8[10],character;

for(i=0;i<=1050;i+=4)

{ outtextxy(k,245,"ÿ");

k++;

}

k=155;

for(i=0;i<=1050;i+=4)

{ outtextxy(k,265,"ÿ");

k++;

}

gotoxy(31,15);gets(str7);

i=0;k=31;

do

{ character=getch(); /* These thing is done so that password is not visible*/

gotoxy(k,17) ;printf("*");

str8[i]=character;

k++;

i++;

Page 12: Linked List Graphics

}while(character != '.');

i--;

str8[i]='\0';

/* NOW COMING THE FILE HANDLING */

FILE *fp;

i=0;flag=0;

fp=fopen("d:\LOGIN.txt","r+");/* login.txt already contains the username n paswd*/

while(fscanf(fp,"%s\t%s\n",l[i].username,l[i].password)!= EOF)

{

if(strcmp(str7,l[i].username)==0 && strcmp(str8,l[i].password)==0)

{ flag=1;

}

i++;

}

settextstyle(10,0,1);

if(flag==0)

{ outtextxy(140,275,"®® ACCESS DENIED ¯¯ ");music(1);music(1);

outtextxy(140,320,"PRESS A KEY TO CONTINUE...");

getch();

count++;

if(count< 3)

{ goto logi; /* i m giving 3 chances in case user make any mistakes */

}

else

exit(0);/* go out of program as access is denied */

}

Page 13: Linked List Graphics

else

{ outtextxy(140,275,"ACCESS GRANTED ¯ ¯ ¯");music(1);music(1);

outtextxy(140,320,"PRESS A KEY TO CONTINUE...");

}

fclose(fp);

getch();

closegraph();

restorecrtmode();

/**********************************************************************************

Now coming to main menu if access granted */

int key;

main:

printmain(); /* WILL PRINT THE MAIN MENU */

gotoxy(45,21);choice=getche();

switch(choice)

{

case '1':

new_employee(); /* APPENDING THE RECORD */

getch();

goto main;

case '2':

clrscr();

Page 14: Linked List Graphics

display(head); /* PRINTING THE RECORDS */

goto main;

case '3':

delete_employee();

goto main;

case '4':

update(); /* MODIFYING THE RECORDS */

goto main;

case '5':

clrscr();

border_margin();

gotoxy(25,6);cprintf("R E C O R D S E A R C H");

gotoxy(5,8);cprintf("ENTER THE EMPLOYEE NUMBER WHICH IS TO BE UPDATED : ");

gotoxy(57,8);scanf("%d",&key);

search_employee(key);

getch();

goto main;

case '6':

border_margin();

gotoxy(25,11);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,11);cprintf("ÿ");

Page 15: Linked List Graphics

k++;

}

gotoxy(50,11);cprintf("»");

gotoxy(25,12);cprintf("º º");

gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,13);cprintf("ÿ");

k++;

}

gotoxy(32,9);cprintf("QUITING ....");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");delay(50);

k++;

}

gotoxy(22,19);textcolor(YELLOW + BLINK);

cprintf("PRESS A KEY TO RETURN TO WINDOWS");

gotoxy(30,17);textcolor(YELLOW);cprintf("B Y E B Y E !!");

gotoxy(24,79);

getch();

break;

default:

goto main;

Page 16: Linked List Graphics

}

}

void new_employee()

{ clrscr();

border_margin();

employee *emp;

textcolor(YELLOW);

gotoxy(25,3);cprintf("E N T E R I N G R E C O R D");

printdetail();

if(head==NULL&&tail==NULL)

{ count++;

emp=getnode(count);

head=emp;

tail=emp;

emp->previousptr=NULL;

emp->nextptr=NULL;

}

else

{ count++;

emp=getnode(count);

emp->previousptr=tail;

tail->nextptr=emp;

emp->nextptr=NULL;

Page 17: Linked List Graphics

tail=emp;

}

}

void display(employee *temp)

{ if(head==NULL) /* EMPTY LINKED LIST */

{ clrscr();

border_margin();

gotoxy(25,10);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,10);cprintf("ÿ");

k++;

}

gotoxy(50,10);cprintf("»");

gotoxy(25,11);cprintf("º NO RECORDS AVAILABLE º");

gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");

k++;

}

}

else

{ if(temp==head)

do

Page 18: Linked List Graphics

{ clrscr();

border_margin();

gotoxy(25,5);cprintf("P R I N T I N G R E C O R D");

printdetail();

gotoxy(20,7);cprintf("%d",temp->employee_no);

gotoxy(20,9);puts(temp->employee_name);

gotoxy(20,11);cprintf("%f",temp->grosspay);fflush(stdin);

gotoxy(20,13);puts(temp->designation);

gotoxy(20,15);cprintf("%d",temp->age);fflush(stdin);

gotoxy(20,17);puts(temp->sex);

gotoxy(25,20);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,20);cprintf("ÿ");

k++;

}

gotoxy(50,20);cprintf("»");

gotoxy(25,21);cprintf("º HIT KEY FOR NEXT RECORDº");

gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,22);cprintf("ÿ");

k++;

}

getch();

Page 19: Linked List Graphics

temp=temp->nextptr;

}while(temp!=NULL);

}

}

void delete_employee()

{

int key,flag;

employee *temp;

temp=head;

if(head==NULL) /* EMPTY LINKED LIST */

{ clrscr();

border_margin();

gotoxy(25,10);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,10);cprintf("ÿ");

k++;

}

gotoxy(50,10);cprintf("»");

gotoxy(25,11);cprintf("º NO RECORDS AVAILABLE º");

gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");

k++;

Page 20: Linked List Graphics

}

goto last;

}

else

{ clrscr();

border_margin();

gotoxy(10,7);cprintf("ENTER THE EMPLOYEE NUMBER YOU WANT TO DELETE : ");

gotoxy(55,7);scanf("%d",&key);

border_margin();

gotoxy(25,11);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,11);cprintf("ÿ");

k++;

}

gotoxy(50,11);cprintf("»");

gotoxy(25,12);cprintf("º º");

gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,13);cprintf("ÿ");

k++;

}

gotoxy(25,9);cprintf("SEARCHING FOR RECORDS ...");

k=26;

for(i=1;i<=24;i++)

Page 21: Linked List Graphics

{ gotoxy(k,12);cprintf("ÿ");delay(50);

k++;

}

gotoxy(22,19);textcolor(YELLOW);

cprintf("PRESS A KEY TO RETURN TO CONTINUE ...");

gotoxy(28,17);cprintf("SEARCHING COMPLETE");

getch();

/* traverse the entire linked list */

while(temp!=NULL)

{ if(temp->employee_no == key)

{ flag++;

if(temp==head) /* if node is first */

{ head=head->nextptr;

head->previousptr=NULL;

}

else

{ if(temp->nextptr==NULL) /* if node is last */

temp->previousptr->nextptr=NULL;

else

{ temp->previousptr->nextptr = temp->nextptr;

temp->nextptr->previousptr = temp->previousptr;

}

free(temp);

}

}

Page 22: Linked List Graphics

temp=temp->nextptr;

}

}

if(flag==0)

{ clrscr();

border_margin();

gotoxy(25,10);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,10);cprintf("ÿ");

k++;

}

gotoxy(50,10);cprintf("»");

gotoxy(25,11);cprintf("º NO RECORDS FOUND º");

gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");

k++;

}

getch();

}

if(flag==1)

{ clrscr();

border_margin();

gotoxy(25,10);cprintf("É");

Page 23: Linked List Graphics

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,10);cprintf("ÿ");

k++;

}

gotoxy(50,10);cprintf("»");

gotoxy(25,11);cprintf("º RECORD DELETED º");

gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");

k++;

}

getch();

}

last:

getch();

}

void update()

{ int choice;

char str[30];

char f;

employee *temp;

temp=head;

if(head==NULL) /* EMPTY LINKED LIST */

{ clrscr();

Page 24: Linked List Graphics

border_margin();

gotoxy(25,10);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,10);cprintf("ÿ");

k++;

}

gotoxy(50,10);cprintf("»");

gotoxy(25,11);cprintf("º NO RECORDS AVAILABLE º");

gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");

k++;

}

}

else

{ clrscr();

border_margin();

gotoxy(25,3);cprintf("R E C O R D U P D A T E");

gotoxy(5,5);cprintf("ENTER THE EMPLOYEE NUMBER WHICH IS TO BE UPDATED : ");

gotoxy(57,5);scanf("%d",&choice);

if(choice > count)

{ clrscr();

border_margin();

gotoxy(10,10);cprintf("EMPLOYEE NO NOT FOUND");

Page 25: Linked List Graphics

getch();

goto last;

}

again:

gotoxy(5,10);cprintf("1. NAME ");gotoxy(5,11);cprintf("2. GROSS PAY");

gotoxy(5,12);cprintf("3. DESIGNATION");gotoxy(5,13);cprintf("4. AGE");

gotoxy(5,14);cprintf("5. SEX");

gotoxy(5,16);cprintf("ENTER THE FIELD YOU WANT TO EDIT : ");

gotoxy(41,16);fflush(stdin);f=getch();

switch(f)

{ case '1':

fflush(stdin);

gotoxy(5,18);cprintf("ENTER NEW NAME : ");gets(str);

while(choice!=temp->employee_no)

temp=temp->nextptr;

clrscr();

printdetail();

gotoxy(20,7);printf("%d",temp->employee_no);

strcpy(temp->employee_name,str);

gotoxy(20,9);printf("%s",temp->employee_name);

gotoxy(20,11);printf("%f",temp->grosspay);

gotoxy(20,13);puts(temp->designation);

gotoxy(20,15);printf("%d",temp->age);

gotoxy(20,17);puts(temp->sex);

break;

case '2':

Page 26: Linked List Graphics

float gp;

fflush(stdin);

gotoxy(20,18);cprintf("ENTER NEW GROSS : ");scanf("%f",&gp);

while(choice!=temp->employee_no)

temp=temp->nextptr;

clrscr();

printdetail();

gotoxy(20,7);printf("%d",temp->employee_no);

temp->grosspay = gp;

gotoxy(20,9);printf("%s",temp->employee_name);

gotoxy(20,11);printf("%f",temp->grosspay);

gotoxy(20,13);puts(temp->designation);

gotoxy(20,15);printf("%d",temp->age);

gotoxy(20,17);puts(temp->sex);

break;

case '3':

fflush(stdin);

gotoxy(20,18);cprintf("ENTER NEW DESIGNATION : ");gets(str);

while(choice!=temp->employee_no)

temp=temp->nextptr;

clrscr();

printdetail();

gotoxy(20,7);printf("%d",temp->employee_no);

strcpy(temp->designation,str);

gotoxy(20,9);printf("%s",temp->employee_name);

gotoxy(20,11);printf("%f",temp->grosspay);

Page 27: Linked List Graphics

gotoxy(20,13);puts(temp->designation);

gotoxy(20,15);printf("%d",temp->age);

gotoxy(20,17);puts(temp->sex);

break;

case '4':

int gp1;

fflush(stdin);

gotoxy(20,18);cprintf("ENTER NEW AGE : ");scanf("%d",&gp1);

while(choice!=temp->employee_no)

temp=temp->nextptr;

clrscr();

printdetail();

gotoxy(20,7);printf("%d",temp->employee_no);

temp->age = gp1;

gotoxy(20,9);printf("%s",temp->employee_name);

gotoxy(20,11);printf("%f",temp->grosspay);

gotoxy(20,13);puts(temp->designation);

gotoxy(20,15);printf("%d",temp->age);

gotoxy(20,17);puts(temp->sex);

break;

case '5':

fflush(stdin);

gotoxy(20,18);cprintf("ENTER NEW SEX : ");gets(str);

while(choice!=temp->employee_no)

temp=temp->nextptr;

clrscr();

Page 28: Linked List Graphics

printdetail();

gotoxy(20,7);printf("%d",temp->employee_no);

strcpy(temp->sex,str);

gotoxy(20,9);printf("%s",temp->employee_name);

gotoxy(20,11);printf("%f",temp->grosspay);

gotoxy(20,13);puts(temp->designation);

gotoxy(20,15);printf("%d",temp->age);

gotoxy(20,17);puts(temp->sex);

break;

default:

goto again;

}

gotoxy(25,20);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,20);cprintf("ÿ");

k++;

}

gotoxy(50,20);cprintf("»");

gotoxy(25,21);cprintf("º RECORD UPDATED º");

gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,22);cprintf("ÿ");

k++;

}

Page 29: Linked List Graphics

}

last:

getch();

}

employee *getnode(int count)

{ employee *nodeptr;

nodeptr=(employee *)malloc(sizeof(employee));

nodeptr->employee_no=count;

gotoxy(20,7);printf("%d",nodeptr->employee_no);fflush(stdin);

gotoxy(20,9);gets(nodeptr->employee_name);

gotoxy(20,11);scanf("%f",&nodeptr->grosspay);fflush(stdin);

gotoxy(20,13);gets(nodeptr->designation);

gotoxy(20,15);scanf("%d",&nodeptr->age);fflush(stdin);

gotoxy(20,17);gets(nodeptr->sex);

gotoxy(25,20);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,20);cprintf("ÿ");

k++;

}

gotoxy(50,20);cprintf("»");

gotoxy(25,21);cprintf("º RECORD ENTRY SUCESSFUL º");

gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,22);cprintf("ÿ");

Page 30: Linked List Graphics

k++;

}

nodeptr->previousptr=NULL;

nodeptr->nextptr=NULL;

return nodeptr;

}

void search_employee(int key)

{ employee *temp;

clrscr();

border_margin();

gotoxy(25,11);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,11);cprintf("ÿ");

k++;

}

gotoxy(50,11);cprintf("»");

gotoxy(25,12);cprintf("º º");

gotoxy(25,13);cprintf("È");gotoxy(50,13);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,13);cprintf("ÿ");

k++;

}

gotoxy(32,9);cprintf("SEARCHING...");

k=26;

Page 31: Linked List Graphics

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");delay(50);

k++;

}

gotoxy(22,19);textcolor(YELLOW);

cprintf("PRESS A KEY TO RETURN TO CONTINUE >>");

gotoxy(28,17);cprintf("SEARCHING COMPLETE");

getch();

temp=head;

int flag=0;

if(temp==NULL) /* LINKED LIST IS EMPTY */

{ clrscr();

border_margin();

gotoxy(25,10);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,10);cprintf("ÿ");

k++;

}

gotoxy(50,10);cprintf("»");

gotoxy(25,11);cprintf("º NO RECORDS AVAILABLE º");

gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");

k++;

Page 32: Linked List Graphics

}

music(1);music(1);

goto last;

}

while(temp!=NULL)

{ if(temp->employee_no==key)

{ flag++;

printdetail();

gotoxy(20,7);printf("%d",temp->employee_no);

gotoxy(20,9);puts(temp->employee_name);

gotoxy(20,11);printf("%f",temp->grosspay);

gotoxy(20,13);gets(temp->designation);

gotoxy(20,15);printf("%d",temp->age);

gotoxy(20,17);puts(temp->sex);

gotoxy(25,20);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,20);cprintf("ÿ");

k++;

}

gotoxy(50,20);cprintf("»");

gotoxy(25,21);cprintf("º RECORD FOUND º");

gotoxy(25,22);cprintf("È");gotoxy(50,22);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,22);cprintf("ÿ");

Page 33: Linked List Graphics

k++;

}

music(1);music(1);

}

temp=temp->nextptr;

}

if(flag==0)

{ clrscr();

border_margin();

clrscr();

border_margin();

gotoxy(25,10);cprintf("É");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,10);cprintf("ÿ");

k++;

}

gotoxy(50,10);cprintf("»");

gotoxy(25,11);cprintf("º RECORDS NOT FOUND º");

gotoxy(25,12);cprintf("È");gotoxy(50,12);cprintf("¼");

k=26;

for(i=1;i<=24;i++)

{ gotoxy(k,12);cprintf("ÿ");

k++;

}

}

Page 34: Linked List Graphics

last:

}

void border_margin()

{ clrscr();

textcolor(YELLOW);

int i,j=3;

gotoxy(2,2);cprintf("É");

for(i=0;i<74;i++)

{ gotoxy(j,2);cprintf("ÿ");

j++;

}

gotoxy(77,2);cprintf("»");

j=3;

for(i=0;i<20;i++)

{ gotoxy(2,j) ;cprintf("º");

gotoxy(77,j);cprintf("º");

j++;

}

gotoxy(2,23);cprintf("È");

j=3;

for(i=0;i<74;i++)

{ gotoxy(j,23);cprintf("ÿ");

j++;

}

gotoxy(77,23);cprintf("¼");

}

Page 35: Linked List Graphics

void printmain()

{ int k,i;

border_margin(); /* user defined function to draw margin */

textbackground(0); /* sets background none */

textcolor(YELLOW);/* set text color */

textbackground(RED);

gotoxy(6,4);cprintf("É");

k=7;

for(i=1;i<=24;i++)

{ gotoxy(k,4);cprintf("ÿ");

k++;

}

gotoxy(31,4);cprintf("»");

gotoxy(6,5);cprintf("º 1. ADD RECORDS º");

gotoxy(6,6);cprintf("È");gotoxy(31,6);cprintf("¼");

k=7;

for(i=1;i<=24;i++)

{ gotoxy(k,6);cprintf("ÿ");

k++;

}

gotoxy(43,4);cprintf("É");

k=44;

for(i=1;i<=24;i++)

{ gotoxy(k,4);cprintf("ÿ");

k++;

Page 36: Linked List Graphics

}

gotoxy(68,4);cprintf("»");

gotoxy(43,5);cprintf("º 2. DISPLAY RECORDS º");

gotoxy(43,6);cprintf("È");gotoxy(68,6);cprintf("¼");

k=44;

for(i=1;i<=24;i++)

{ gotoxy(k,6);cprintf("ÿ");

k++;

}

gotoxy(6,9);cprintf("É");

k=7;

for(i=1;i<=24;i++)

{ gotoxy(k,9);cprintf("ÿ");

k++;

}

gotoxy(31,9);cprintf("»");

gotoxy(6,10);cprintf("º 3. DELETE RECORDS º");

gotoxy(6,11);cprintf("È");gotoxy(31,11);cprintf("¼");

k=7;

for(i=1;i<=24;i++)

{ gotoxy(k,11);cprintf("ÿ");

k++;

}

gotoxy(43,9);cprintf("É");

k=44;

Page 37: Linked List Graphics

for(i=1;i<=24;i++)

{ gotoxy(k,9);cprintf("ÿ");

k++;

}

gotoxy(68,9);cprintf("»");

gotoxy(43,10);cprintf("º 4. UPDATE RECORDS º");

gotoxy(43,11);cprintf("È");gotoxy(68,11);cprintf("¼");

k=44;

for(i=1;i<=24;i++)

{ gotoxy(k,11);cprintf("ÿ");

k++;

}

gotoxy(6,14);cprintf("É");

k=7;

for(i=1;i<=24;i++)

{ gotoxy(k,14);cprintf("ÿ");

k++;

}

gotoxy(31,14);cprintf("»");

gotoxy(6,15);cprintf("º 5. SEARCH FOR RECORDS º");

gotoxy(6,16);cprintf("È");gotoxy(31,16);cprintf("¼");

k=7;

for(i=1;i<=24;i++)

{ gotoxy(k,16);cprintf("ÿ");

k++;

}

Page 38: Linked List Graphics

gotoxy(43,14);cprintf("É");

k=44;

for(i=1;i<=24;i++)

{ gotoxy(k,14);cprintf("ÿ");

k++;

}

gotoxy(68,14);cprintf("»");

gotoxy(43,15);cprintf("º 6. QUIT º");

gotoxy(43,16);cprintf("È");gotoxy(68,16);cprintf("¼");

k=44;

for(i=1;i<=24;i++)

{ gotoxy(k,16);cprintf("ÿ");

k++;

}

gotoxy(25,21);cprintf("ENTER YOUR CHOICE : ");

}

void printdetail()

{ border_margin();

gotoxy(5,7);cprintf("EMPLOYEE NO : ");

gotoxy(20,8);cprintf("____________________________________________");

gotoxy(5,9);cprintf("NAME : ");

gotoxy(20,10);cprintf("____________________________________________");

gotoxy(5,11);cprintf("GROSS PAY : ");

gotoxy(20,12);cprintf("____________________________________________");

gotoxy(5,13);cprintf("DESIGNATION : ");

gotoxy(20,14);cprintf("____________________________________________");

Page 39: Linked List Graphics

gotoxy(5,15);cprintf("AGE : ");

gotoxy(20,16);cprintf("____________________________________________");

gotoxy(5,17);cprintf("SEX : ");

gotoxy(20,18);cprintf("____________________________________________");

}

References-

1.en.wikipedia.org/wiki/Doubly_linked_list

2. www.iitk.ac.in/esc101/08Jan/lecnotes/lecture35.pdf

3. thecodecracker.com/c-programming/double-linked-list

4. library.maemodocs.nokia.com/.../glib-Doubly-Linked-Lists.html

**********************END**********************