stack n queue using linked list

Upload: rahul-kumar

Post on 03-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 stack n queue using linked list

    1/141

    INDEX

    CHAPTER

    NO.

    TITLE PAGE NO.

    1.

    Introduction

    1.1 About the Project Problem 1

    1.2Methods Of Linked List

    2.

    System Study

    2.1 Current system & its limitations

    2.2 Proposed system 4

    2.3 Objectives

    2.4 Feasibility studies

    3.System Analysis3.1 Analysis 7

    3.2 System Diagram

    4.

    System Design

    4.1 About the environment 11

    5.

    Code

    5.1 Source code

    5.2 Input and Output Designs 18

    6. User Manual 132

    7.

    Conclusion

    7.1 Scope 134

    7.2Limitations

    8.Bibliography 136

    1

  • 7/28/2019 stack n queue using linked list

    2/141

    1. Introduction to Project

    1.1 About the Project

    Stack N Queue using linked list in Graphics is developed by using OOP WITH C++.

    It included many features, which not only attract users of it but also inspires the programmers

    who want to make good Application in C++. It is extremely user friendly; fully animated with

    the additional features that experienced users need not follow in multiple level menus. Also it

    gives other important features like calculating the total time for each sorting techniques.

    The project named Stack N Queue can be used to perform push and pop operation on

    stack and insert and delete operation on queue which you would normally use by a very complex

    paper work.

    1.2 Description about methods of Linked List

    Linked list:

    A Linked list is a chain of elements in which each element consists of data as well as a

    link to the next element. The link stores the address of the next logically similar element in the

    list.

    Stack as a Linked list:

    The linked list representation of a stack, commonly termed linked stack

    is a stack that is implemented using a singly linked list. The INFO fields of the nodes hold the

    elements of the stack and the LINK fields hold pointers to the neighboring element in the stack.

    The START pointers of the linked list behaves as the TOP pointers variable of the stack and the

    NULL pointers of the last node in the list signals the bottom of stack.

    INFO LINK

    Top of stack Bottom of stack

    2

    Data

    Address

    of

    Next node

    xxx yyy zzz

  • 7/28/2019 stack n queue using linked list

    3/141

    A push operation into STACK is accomplished by inserting a node into the front or start of the

    list and a pop operation is undertaken by deleting the node pointed to by the START pointers.

    Push www into Stack

    STACK before push operation:

    Top

    STACK after push operation:

    Top

    Pop from STACK

    Top

    STACK after pop operations:

    Top Top

    Queue as a Linked list:

    A linked queue is a queue implemented as a linked list with two pointersvariables FRONT and REAR pointing to the nodes which is in the FRONT and REAR of the

    queue. The INFO fields of the list hold the elements of the queue and the LINK fields hold

    pointers to the neighboring element in the queue.

    Queue Q:

    3

    xxx yyy zzz

    www xxx yyy zzz

    xxx yyy zzz

    xxx yyy zzz

    AAA BBB CCC DDD X

  • 7/28/2019 stack n queue using linked list

    4/141

    Front Rear

    The Rear pointer is updated to point to the last node just added to the list. In the case of

    deletion, the first node of the list pointed to by FRONT is deleted and the FRONT pointer is

    updated to point to the next node in the list.

    Insert EEE into queue Q:

    Front Rear Rear

    Delete from queue Q

    Front Front Rear

    4

    AAA BBB CCC DDD X EEE X

    AAA BBB CCC DDD EEE X

  • 7/28/2019 stack n queue using linked list

    5/141

    5

    Chapter No.2

    SYSTEM STUDY

  • 7/28/2019 stack n queue using linked list

    6/141

    2. System study

    2.1 Current Manual system & its limitations:

    In manual system, a paper work is maintained for performing sorting

    Techniques. Each technique is performing separately using paper work and there is need

    to draw various diagrams to understand the working of Linked list. It consumes lot oftime and some times process will become more confusing and critical and it will become

    very difficult to understand how it works. It will take lot of manual efforts for drawing

    each diagram of stack & queue using linked list and stack & queue using double ended

    linked list..

    2.2Proposed System Computerized System resembles old manual system. It Perform the operation

    automatically, which hold track of all operation. It contains correct track. Operation

    process is fast and it takes legal inputs so less time required for showing theprocess . System will show the animation of selected sorting technique to user so that

    user can easily understand how the process is carried out.

    2.3 ObjectivesBy doing computerization of system, many goals can be attained. Computer can achievetremendous speed. To show the animated steps for each Linked list is objectives of oursystem. These are some other objectives of system.

    To computerize the current manual system.

    To make system a user friendly so that working on a system becomes

    easy for users.

    To provide the user with user friendly system that will satisfy his

    requirement and help him to work comfortably system.

    To reduce man power and associated disadvantages.

    6

  • 7/28/2019 stack n queue using linked list

    7/141

    2.4 Feasibility Studies

    The organization already has required hardware and software other technical

    equipments. Hence the system will be technically feasible.

    a) Operational Social Feasibility:

    This system is very easy to understand for Teachers and students, so that

    there is no need to appoint a new person. Hence, computerization of drawing

    System would be socially feasible.

    b) Economic Feasibility:The Project does not require any heavy extra expenses for Analysis and design of

    new system. Student can operate and maintain the system with available facilities.

    Benefits acquire by installation of system are immense. Tangible benefits, which

    can be evaluated in money otherwise, quantified.

    In tangible benefits include developer satisfaction. It also helpful to students as

    they save time and paper cost.

    7

  • 7/28/2019 stack n queue using linked list

    8/141

    8

    Chapter No 3

    SYSTEM ANALYSIS

  • 7/28/2019 stack n queue using linked list

    9/141

    3 SYSTEM ANALYSIS

    3.1Analysis

    A) System Analysis:

    System analysis & design is concerned with manmade system involving.

    A system can be defined as a set of interfacing elements responding from inputs to

    outputs. Each system is composed of subsystem, which are further made of sub systems.

    The interconnections between sub systems are known as interface. The system concept

    requires the system analyst to look after the system as whole.

    System will analyze in terms of their objectives and inputs, Processes and outputs

    required achieving these objectives.

    System analyst is concerned with analyzing system with a view to make them more by

    modification or by substantial redesign.

    The real essence of system design is dividing a system that needs the proceeding

    requirements. It involves creation and development of new, inputs, methods, procedures

    and outputs for processing data that continue to objectives. To put it in way creativity

    is a requirement for the knowledge of technique itself. It is formed as a science because

    its approach is scientific.

    *During the system analysis phase, the information about the LINKED LIST was

    collected, through various mediums such as, from Books available in library, through

    Internet, and through interaction with concerned professor.

    9

    INPUTPROCESS OUTPUT

  • 7/28/2019 stack n queue using linked list

    10/141

    Based on the information collected, the it was decided that development of the system is

    to be divided in Four different phases, i.e;

    i) Introduction Part

    ii) Information part

    iii) Operation Part

    iv) Introduction to Advanced Concepts.

    b) System Design:

    As per the points decided , design of the system was carried out.

    i) Introduction Part : Introduction part contains the introduction of the subject

    in a brief format.

    ii) Information Part : Information of each topic is given in simple to complex

    order . Various related concept is discussed on each page.Information of each

    operation and how to perform it is also given along with a solved example.

    iii) Operation Part : User can perform various operations by inputting data and

    viewing the output on the same screen or in some cases, ona different screen.

    Input design and output design is also prepared for the convenience of the

    user.

    In Software design phase , it was decided to use C++ as a language.

    The code is written using arrays and using in-built Graphics functions.The

    code is so written, that user can easily understand it.

    iv) Introduction to Advanced Concepts : The advanced concepts are well

    discussed in the end part of the project.

    10

  • 7/28/2019 stack n queue using linked list

    11/141

    3.2 System Diagram

    Structured Chart of System work

    11

    LINKED LIST

    DOUBLE ENDED

    LINKED LIST

    QueueStack

    Stack Queue

  • 7/28/2019 stack n queue using linked list

    12/141

    12

    Chapter No.4

    SYSTEM DESIGN

  • 7/28/2019 stack n queue using linked list

    13/141

    4. SYSTEM DESIGN:

    4.1 About the Environment

    1 Platform Used

    C++ has developed by BJARNE STROUSTRUP at AT & T BELL Laboratories.

    C++ is derived from the c language .It is compatible With c (it is actually a

    superset ).So that exiting c code can be incur ported into c++ programs . The mostimportant element s added to c to create c++ are concern with classes ,objects and

    object oriented programming.

    C++ programs are fast and efficient ,qualities , which helped make C an

    extremely popular programming language .however, it scarifies Some flexibility in

    order to remain efficient . C++ uses compile time Binding ,which means that the

    programmer must specified the specific Class of an object or at a very least ,themost general class that an Object can be belong to. This provides high run time

    efficiency & Code size, but it trades off some of the power to reuse classes.

    C++ has become so popular most new C compilers are actually C/C++ compilers.

    However, to take full advantage of oops ,one must program and think in C++.This

    can often be a major problem for experienced c programmers. Many programmersthink they are coding in c++, but instead are only using a small languages object

    oriented power.

    Applications of C++

    1. C++ is versatile language for handling very large programs

    2. We can create hierarchy related objects, we build special

    Object oriented libraries which can be used later by programmers.

    3. C++ is able to map the real world problem properly; C part of C++ gives thelanguage the ability to get close to machine level details.

    4. C++ programs are easily maintained & expandable

    1) Arrays :An Array can be defined as an infinite collection of homogenous (similar

    type) elements. The simplest form of array is a one dimensional array, that maybe defined as a finite ordered set of homogenous elements.

    One dimensional array can be declared as data_ type var_name [constant]

    The declaration int a [100] reserves 100 successive memory locations, each largeenough to contain a single integer. The address of the first of these locations is

    called the base address of array a.

    13

  • 7/28/2019 stack n queue using linked list

    14/141

    Arrays like simple variables can also be passed to function. To pass, its

    name is written inside the argument list in the call statement. Arrays are by

    default passed to function by call by reference method, because array name is

    itself a pointer to first memory location of array.For Example: float avg (float avg [], int size)

    2) Inheritance :A key feature of C++ classes is inheritance. Inheritance allows creating classes

    which are derived from other classes, so that they automatically include some of its

    "parent's" members, plus its own. For example, we are going to suppose that we want todeclare a series of classes that describe polygons like our CRectangle, or like CTriangle.

    They have certain common properties, such as both can be described by means of only

    two sides: height and base.This could be represented in the world of classes with a class CPolygon from which we

    would derive the two other ones: CRectangle and CTriangle.

    The class CPolygon would contain members that are common for both types of polygon. In our

    case: width and height. And CRectangle and CTriangle would be its derived classes, with specificfeatures that are different from one type of polygon to the other.

    In order to derive a class from another, we use a colon (:) in the declaration of the

    derived class using the following format:

    class derived_class_name: public base_class_name

    { /*...*/ };

    3) Polymorphism:Polymorphism is a powerful feature of the object oriented programming language C++. A single

    operator + behaves differently in different contexts such as integer, float or strings referring the conceptofpolymorphism. The above concept leads to operatoroverloading. The concept of overloading is also a

    branch ofpolymorphism. When the exiting operator or function operates on new data type it isoverloaded. This feature of polymorphism leads to the concept ofvirtual methods.

    C++ provides three different types of polymorphism.

    Virtual functions

    Function name overloading

    14

  • 7/28/2019 stack n queue using linked list

    15/141

    Operator overloading

    4) Functions:

    Using functions we can structure our programs in a more modular way, accessingall the potential that structured programming can offer to us in C++.

    A function is a group of statements that is executed when it is called from some pointof the program. The following is its format:

    type name ( parameter1, parameter2, ...) { statements } where:

    Type is the data type specifies of the data returned by the function.

    Name is the identifier by which it will be possible to call the function.

    Parameters (as many as needed): Each parameter consists of a data type specifies

    followed by an identifier, like any regular variable declaration (for example: int

    x) and which acts within the function as a regular local variable. They allowpassing arguments to the function when it is called. The different parameters are

    separated by commas.

    Statements are the function's body. It is a block of statements surrounded by

    braces { }.

    5) Friend Function:In principle, private and protected members of a class cannot be accessed from outside the same

    class in which they are declared. However, this rule does not affect friends.Friends are functions or

    classes declared with the friend keyword.If we want to declare an external function as friend of a

    class, thus allowing this function to have access to the private and protected members of this class, we

    do it by declaring a prototype of this external function within the class, and preceding it with the

    keywordfriend

    :

    15

  • 7/28/2019 stack n queue using linked list

    16/141

    Inbuilt Function

    NO Function Header File Explanation

    1 Rectangle

    draw the rectangle2 Lline Draw line with coordinates

    3 Bar3d Draw 3d bar

    4 Settextstyle Setting textstyles for text

    5 Bar Draws bar

    6 Circle Draws circle

    7 Closegraph Shuts down the graphics system

    8 Getmaxx Returns maximum x or y screen

    coordinate9 Getmaxy

    10 Graphresult Returns error code for the last

    unsuccessful graphics operations

    11 Initgraph Initializes the graphics system

    12 Outtextxy Displays a string at the specified location

    13 restorecrtmode Restores screen mode to pre-initgraph

    setting

    14 Setcolor Sets the current drawing color

    15 Setfillstyle Sets the fill pattern and color

    16 Settextstyle Sets the current text characteristics17 Textwidth Return the width of a string in pixels

    H/W & S/W Requirement :-

    Developer Side:-

    Processor Pentium I ,II ,III ,IV

    16

  • 7/28/2019 stack n queue using linked list

    17/141

    Operating System Windows 98,2000Professional Windows XP

    Software Requirements

    Operating System : windows 98, 2000 professional, Windows XP

    Database : Turbo charger - Bin

    Recommended Requirements:

    Hardware Requirements

    CPU : 2.0 GHz

    RAM : 512 + MBHard Disc : 120 GB

    Software Requirements

    Operating System : Win98, Win NT or Win 2000

    Database : Turbo-charger - Bin

    User Side:-

    Processor Pentium I, II, III, IV

    Operating system Windows 98,2000Professional Windows

    XP

    Software Requirement for the System:-

    This project can run on any Microsoft Windows platform. This project can

    smoothly run on Windows 95/98/2000 and Windows XP with 1024 X 768 resolutions.

    17

  • 7/28/2019 stack n queue using linked list

    18/141

    Hardware Requirement for the System :-

    The Hardware requirement for the system is mainly depend on the operating

    system used by the user. The standard requirements are (i) HDD 512 MB(min) (ii)RAM

    32 MB

    18

  • 7/28/2019 stack n queue using linked list

    19/141

    5. SYSTEM CODING

    a. Source Code

    19

    Chapter No.5

    CODE

  • 7/28/2019 stack n queue using linked list

    20/141

    /* Project : Graphical Representation of Linked List

    By : Avinash Kumar Sinha

    Roll No. :02

    Date : 18/04/2011 */

    #include

    #include

    #include

    #include

    #include

    #include

    #include

    #include#define size 20

    #define STSIZE 20

    //---------------------- CONSTANT VARIABLES -------------//

    # define INSERT 0

    # define DELETE 1

    # define NORMAL 0# define WARNING 1

    # define PUSH 0

    # define POP 1

    Void screen();

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

    //---------------------- CLASS DEFINITION ----------------

    class Linked_list_Stack

    {

    private:

    char fill_pattern[8];

    20

  • 7/28/2019 stack n queue using linked list

    21/141

    int pushed_element_count;

    struct node

    {

    long data;

    node *next;

    };

    node *top;

    node *entry;

    node *print;

    node *bottom;

    node *last_entry;node *second_last_entry;

    public:

    Linked_list_Stack( );

    long get_element( );

    void pop( );

    void push( );

    void print_linked_list( );

    void show_working( );void show_main_screen( );

    void waiting_for_input( );

    void show_element_screen(int);

    void clear_element_screen(int);

    void show_push_pop_screen(int);

    void show_output_screen( );

    void show_window(int,int,int,int);

    };

    //--------------------- FUNCTION DEFINITIONS --------------

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

    //---------------------- Linked_list_Stack( ) ------------

    21

  • 7/28/2019 stack n queue using linked list

    22/141

    Linked_list_Stack::Linked_list_Stack ( )

    {

    top=NULL;

    bottom=NULL;

    pushed_element_count=0;

    fill_pattern[0]=0xAA;

    fill_pattern[1]=0x55;

    fill_pattern[2]=0xAA;

    fill_pattern[3]=0x55;

    fill_pattern[4]=0xAA;

    fill_pattern[5]=0x55;

    fill_pattern[6]=0xAA;fill_pattern[7]=0x55;

    }

    //-------------------- show_window(int,int,int,int) -------

    void Linked_list_Stack::show_window(int x_1,int y_1,int

    x_2,int y_2)

    {setcolor(15);

    rectangle(x_1,y_1,x_2,y_2);

    rectangle(x_1+1,y_1+1,x_2-1,y_2-1);

    setcolor(7);

    rectangle(x_1+2,y_1+2,x_2-2,y_2-2);

    rectangle(x_1+3,y_1+3,x_2-3,y_2-3);

    rectangle(x_1+4,y_1+4,x_2-4,y_2-4);

    setcolor(8);

    rectangle(x_1+5,y_1+5,x_2-5,y_2-5);

    rectangle(x_1+6,y_1+6,x_2-6,y_2-6);

    rectangle(x_1+7,y_1+7,x_2-7,y_2-7);

    }

    22

  • 7/28/2019 stack n queue using linked list

    23/141

    //---------------------- show_main_screen( ) ------------

    void Linked_list_Stack ::show_main_screen( )

    {

    setcolor(15);

    setlinestyle(1,0,3);

    rectangle(5,5,getmaxx( )-5,getmaxy( )-5);

    setlinestyle(0,0,0);

    show_window(5,5,getmaxx( )-5,80);

    setfillpattern(fill_pattern,4);

    bar(13,13,getmaxx( )-13,72);

    settextstyle(3,0,4);

    setcolor(0);outtextxy(17,22,"Implementation of Linked List as Stack");

    outtextxy(18,22,"Implementation of Linked List as

    Stack");

    setcolor(14);

    outtextxy(19,20,"Implementation of Linked List as Stack");

    outtextxy(20,20,"Implementation of Linked List as

    Stack");

    outtextxy(21,20,"Implementation of Linked List asStack");

    show_window(5,82,305,getmaxy( )-5);

    setfillpattern(fill_pattern,9);

    bar(14,91,296,getmaxy( )-14);

    setcolor(6);

    setfillstyle(1,6);

    pieslice(215,105,0,360,10);

    setcolor(2);

    setfillstyle(1,2);

    pieslice(245,105,0,360,10);

    setcolor(4);

    setfillstyle(1,4);

    pieslice(275,105,0,360,10);

    23

  • 7/28/2019 stack n queue using linked list

    24/141

    setcolor(7);

    circle(215,105,11);

    circle(245,105,11);

    circle(275,105,11);

    show_window(307,82,getmaxx( )-5,getmaxy( )-5);

    settextstyle(7,0,4);

    setcolor(0);

    outtextxy(16,111,"Press:");

    setcolor(10);

    outtextxy(17,110,"Press:");

    outtextxy(18,110,"Press:");

    settextstyle(2,0,6);setcolor(0);

    outtextxy(59,151,"

    to Push an Element");

    outtextxy(59,171," to Pop an Element");

    outtextxy(59,191," to Exit");

    setcolor(14);

    outtextxy(60,150,"

    to Push an Element");

    outtextxy(61,150,"

    to Push an Element");

    outtextxy(60,170," to Pop an Element");

    outtextxy(61,170," to Pop an Element");

    outtextxy(60,190," to Exit");

    outtextxy(61,190," to Exit");

    setfillstyle(2,1);

    bar(317,92,getmaxx( )-15,getmaxy( )-15);

    }

    //------------------- show_output_screen( ) ----------

    void Linked_list_Stack::show_output_screen( )

    24

  • 7/28/2019 stack n queue using linked list

    25/141

    {

    for(int count=0;countData pointing arrow */

    line(352,455,415,455);

    line(412,452,415,455);

    line(412,458,415,455);

    25

  • 7/28/2019 stack n queue using linked list

    26/141

    line(382,423,382,443); /* Entry->Next pointing arrow */

    line(382,443,415,443);

    line(412,440,415,443);

    line(412,446,415,443);

    setfillstyle(1,15);

    pieslice(382,420,0,360,2);

    settextstyle(0,0,1);

    setcolor(15);

    outtextxy(320,402,"*");

    setcolor(9);

    outtextxy(420,452,"Entry->Data");

    outtextxy(420,438,"Entry->Next (x=NULL)");

    setcolor(11);

    outtextxy(333,417,"00000");

    }

    //------------------- show_push_pop_screen(int) --------

    Void Linked_list_Stack::show_push_pop_screen(int NORMAL_WARNING)

    {

    int x_1;

    int x_2;

    int y_1;

    int y_2;

    if(NORMAL_WARNING==NORMAL)

    {

    x_1=20;

    x_2=280;

    26

  • 7/28/2019 stack n queue using linked list

    27/141

    y_1=277;

    y_2=350;

    }

    if(NORMAL_WARNING==WARNING)

    {

    x_1=20;

    x_2=280;

    y_1=277;

    y_2=367;

    }

    setcolor(15);setlinestyle(1,0,3);

    rectangle(x_1,y_1,x_2,y_2);

    setlinestyle(0,0,0);

    setcolor(15);

    rectangle(x_1,y_1,x_2,y_2);

    setcolor(7);

    rectangle(x_1+1,y_1+1,x_2-1,y_2-1);

    setcolor(8);

    rectangle(x_1+2,y_1+2,x_2-2,y_2-2);

    setfillstyle(1,9);

    bar(x_1+3,y_1+3,x_2-3,y_2-3);

    }

    //-------------------- show_element_screen(int) ----------

    27

  • 7/28/2019 stack n queue using linked list

    28/141

    void Linked_list_Stack::show_element_screen(int PUSH_POP)

    {

    show_push_pop_screen(NORMAL);

    if(PUSH_POP==PUSH)

    {

    settextstyle(2,0,6);

    setcolor(0);

    outtextxy(28,281,"Enter the Element :");

    setcolor(11);

    outtextxy(29,280,"Enter the Element :");

    outtextxy(30,280,"Enter the Element :");}

    else if(PUSH_POP==POP)

    {

    settextstyle(2,0,6);

    setcolor(0);

    outtextxy(28,281,"Poped Element is :");

    setcolor(11);

    outtextxy(29,280,"Poped Element is :");

    outtextxy(30,280,"Poped Element is :");

    }

    delay(300);

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    29/141

    pieslice(180-count,318,0,360,12);

    pieslice(180+count,318,0,360,12);

    setcolor(15);

    line(180-count,302,180+count,302);

    line(180-count,334,180+count,334);

    arc(180-count,318,90,270,16);

    arc(180+count,318,270,90,16);

    setcolor(7);

    arc(180-count,318,90,270,15);

    arc(180-count,318,90,270,14);

    line(180-count,303,180+count,303);

    line(180-count,304,180+count,304);

    line(180-count,333,180+count,333);

    line(180-count,332,180+count,332);

    arc(180+count,318,270,90,15);arc(180+count,318,270,90,14);

    setcolor(8);

    line(180-count,305,180+count,305);

    line(180-count,331,180+count,331);

    arc(180-count,318,90,270,13);

    arc(180+count,318,270,90,13);

    delay(4);

    }

    }

    29

  • 7/28/2019 stack n queue using linked list

    30/141

    //------------------ clear_element_screen(int) ----------

    Void Linked_list_Stack::clear_element_screen(int NORMAL_WARNING)

    {

    if(NORMAL_WARNING==WARNING)

    {

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    31/141

    {

    show_element_screen(PUSH);

    int count=0;

    char string[6]={'\0'};

    do

    {

    int key_code=0;

    char key=NULL;

    if(kbhit( ))key=getch( );

    key_code=int(key);

    if(key_code>=48 && key_code0)

    {

    setfillstyle(1,0);

    bar(130,306,230,330);

    count--;

    string[count]='\0';

    }

    else if(key_code==13 && count>0)

    break;

    31

  • 7/28/2019 stack n queue using linked list

    32/141

    setcolor(12);

    settextstyle(2,0,7);

    moveto(140,305);

    outtext(string);

    moveto(141,305);

    outtext(string);

    int x=getx( );

    int y=305;

    while(!kbhit( ))

    {

    settextstyle(2,0,7);

    setcolor(12);

    moveto(x+2,y);

    outtext("_");

    delay(250);

    setcolor(0);

    moveto(x+2,y);

    outtext("_");

    delay(200);

    }

    }

    while(count

  • 7/28/2019 stack n queue using linked list

    33/141

    long element=atol(string);

    clear_element_screen(NORMAL);

    return element;

    }

    //----------------------------- push( ) ----------------

    void Linked_list_Stack::push( )

    {

    long num=get_element( );

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    34/141

    sound(1500);

    delay(800);

    nosound( );

    setcolor(2);

    setfillstyle(1,2);

    pieslice(245,105,0,360,10);

    }

    if(pushed_element_count==15)

    {

    setcolor(12);

    setfillstyle(1,12);pieslice(275,105,0,360,10);

    sound(2500);

    delay(1000);

    nosound( );

    setcolor(4);

    setfillstyle(1,4);pieslice(275,105,0,360,10);

    delay(200);

    }

    entry=new(node);

    if(pushed_element_count==15)

    {

    show_push_pop_screen(WARNING);

    settextstyle(7,0,4);

    setcolor(0);

    34

  • 7/28/2019 stack n queue using linked list

    35/141

    outtextxy(25,277,"Error:");

    outtextxy(26,277,"Error:");

    setcolor(14);

    outtextxy(27,275,"Error:");

    outtextxy(28,275,"Error:");

    while(!kbhit( ))

    {

    settextstyle(2,0,8);

    setcolor(0);

    outtextxy(46,309,"Not enough heap");

    outtextxy(47,309,"Not enough heap");

    outtextxy(28,335,"space on Screen.");

    outtextxy(29,335,"space on Screen.");

    setcolor(12);

    outtextxy(48,308,"Not enough heap");

    outtextxy(49,308,"Not enough heap");

    outtextxy(50,308,"Not enough heap");

    outtextxy(30,334,"space on Screen.");

    outtextxy(31,334,"space on Screen.");

    outtextxy(32,334,"space on Screen.");

    delay(500);

    setfillstyle(1,9);

    bar(23,315,277,362);

    delay(400);

    }

    35

  • 7/28/2019 stack n queue using linked list

    36/141

    getch( );

    clear_element_screen(1);

    }

    else if(bottom==NULL)

    {

    entry->data=num;

    entry->next=NULL;

    bottom=entry;

    top=entry;

    pushed_element_count++;

    }

    else

    {

    entry->data=num;

    entry->next=NULL;

    top->next=entry;

    top=entry;

    pushed_element_count++;

    }

    print_linked_list( );

    }

    //-------------------------- pop( ) --------------------

    void Linked_list_Stack::pop( )

    {

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    37/141

    setfillstyle(1,0);

    pieslice(215,105,0,360,10);

    delay(250);

    setcolor(6);

    setfillstyle(1,6);

    pieslice(215,105,0,360,10);

    delay(300);

    }

    if(pushed_element_count==0){

    setcolor(12);

    setfillstyle(1,12);

    pieslice(275,105,0,360,10);

    sound(2500);

    delay(1000);

    nosound( );

    setcolor(4);

    setfillstyle(1,4);

    pieslice(275,105,0,360,10);

    delay(200);

    }

    else if(pushed_element_count>0)

    {

    setcolor(10);

    setfillstyle(1,10);

    pieslice(245,105,0,360,10);

    37

  • 7/28/2019 stack n queue using linked list

    38/141

    sound(3000);

    delay(800);

    nosound( );

    setcolor(2);

    setfillstyle(1,2);

    pieslice(245,105,0,360,10);

    }

    if(bottom==NULL)

    {

    show_push_pop_screen(WARNING);

    settextstyle(7,0,4);

    setcolor(0);

    outtextxy(25,277,"Error:");

    outtextxy(26,277,"Error:");

    setcolor(14);

    outtextxy(27,275,"Error:");outtextxy(28,275,"Error:");

    while(!kbhit( ))

    {

    settextstyle(6,0,4);

    setcolor(0);

    outtextxy(48,306,"Nothing to Pop");

    outtextxy(49,306,"Nothing to Pop");

    setcolor(12);

    outtextxy(50,305,"Nothing to Pop");

    outtextxy(51,305,"Nothing to Pop");

    outtextxy(52,305,"Nothing to Pop");

    38

  • 7/28/2019 stack n queue using linked list

    39/141

    delay(500);

    setfillstyle(1,9);

    bar(23,315,277,350);

    delay(400);

    }

    getch( );

    }

    else

    {for(last_entry=bottom;last_entry->next!=NULL;

    last_entry=last_entry->next)

    second_last_entry=last_entry;

    if(top==bottom)

    bottom=NULL;

    long poped_element=top->data;

    delete(top);

    top=second_last_entry;

    top->next=NULL;

    pushed_element_count--;

    char element[6]={'\0'};

    ltoa(poped_element,element,10);

    show_element_screen(POP);

    39

  • 7/28/2019 stack n queue using linked list

    40/141

    setcolor(12);

    settextstyle(2,0,7);

    outtextxy(140,305,element);

    outtextxy(141,305,element);

    delay(2500);

    }

    clear_element_screen(POP);

    print_linked_list( );

    }

    //---------------------- print_linked_list( ) ----------

    void Linked_list_Stack::print_linked_list( )

    {

    int count=0;

    int x=340;

    int y=100;

    print=bottom;

    setfillstyle(1,0);

    bar(317,92,getmaxx( )-15,getmaxy( )-80);

    while(print!=NULL)

    {

    setcolor(15);

    setlinestyle(0,0,3);

    rectangle(x,y,x+60,y+30);

    char element[6]={'\0'};

    ltoa(print->data,element,10);

    40

  • 7/28/2019 stack n queue using linked list

    41/141

    if(count==0 || count==1 || count==2 || count==6 ||

    count==7 || count==8 || count==12 || count==13 ||

    count==14)

    {

    setfillstyle(1,9);

    bar(x+1,y+1,x+44,y+29);

    setfillstyle(1,1);

    bar(x+46,y+1,x+59,y+29);

    setcolor(15);

    line(x+45,y,x+45,y+30);

    setcolor(11);

    settextstyle(0,0,1);

    outtextxy(x+3,y+10,element);

    if(count==pushed_element_count-1)

    {

    setcolor(15);outtextxy(x+50,y+11,"x");

    }

    }

    else

    {

    setfillstyle(1,9);

    bar(x+16,y+1,x+59,y+29);

    setfillstyle(1,1);

    bar(x+1,y+1,x+14,y+29);

    setcolor(15);

    41

  • 7/28/2019 stack n queue using linked list

    42/141

    line(x+15,y,x+15,y+30);

    if(count==pushed_element_count-1)

    delay(500);

    setcolor(11);

    settextstyle(0,0,1);

    outtextxy(x+18,y+10,element);

    if(count==pushed_element_count-1)

    {

    setcolor(15);

    outtextxy(x+4,y+11,"x");}

    }

    if(count==1 || count==2 || count==7 || count==8 ||

    count==13 || count==14)

    {

    setcolor(15);

    line(x-45,y+15,x,y+15);

    setfillstyle(1,15);

    pieslice(x-47,y+15,0,360,2);

    line(x-6,y+11,x-2,y+15);

    line(x-6,y+19,x-2,y+15);

    }

    else if(count==4 || count==5 || count==10 ||

    count==11)

    {

    setcolor(15);

    line(x+60,y+15,x+105,y+15);

    42

  • 7/28/2019 stack n queue using linked list

    43/141

    setfillstyle(1,15);

    pieslice(x+107,y+15,0,360,2);

    line(x+66,y+11,x+62,y+15);

    line(x+66,y+19,x+62,y+15);

    }

    else if(count==3 || count==9)

    {

    setcolor(15);

    setfillstyle(1,15);

    pieslice(x+53,y-45,0,360,2);

    setlinestyle(0,0,3);

    line(x+55,y-45,x+75,y-45);

    line(x+75,y-45,x+75,y+15);

    line(x+60,y+15,x+75,y+15);

    line(x+62,y+15,x+66,y+11);

    line(x+62,y+15,x+66,y+19);}

    else if(count==6 || count==12)

    {

    setcolor(15);

    setfillstyle(1,15);

    pieslice(x+7,y-45,0,360,2);

    setlinestyle(0,0,3);

    line(x-15,y-45,x+10,y-45);

    line(x-15,y-45,x-15,y+15);

    line(x-15,y+15,x,y+15);

    43

  • 7/28/2019 stack n queue using linked list

    44/141

    line(x-2,y+15,x-6,y+11);

    line(x-2,y+15,x-6,y+19);

    }

    setcolor(7);

    setlinestyle(0,0,3);

    line(350,125,350,138); /* Bottom Arrow */

    line(346,134,350,138);

    line(354,134,350,138);

    setcolor(14);

    settextstyle(2,0,4);

    outtextxy(330,140,"Bottom");

    if(count==pushed_element_count-1)

    {

    setcolor(7);

    setlinestyle(0,0,3);

    line(x+30,y+25,x+30,y+38);

    line(x+26,y+34,x+30,y+38);

    line(x+34,y+34,x+30,y+38);

    setcolor(14);

    settextstyle(2,0,4);

    outtextxy(x+30,y+40,"Top");

    }

    print=print->next;

    count++;

    if(count==0 || count==1 || count==2 || count==6 ||

    count==7 || count==8 || count==12 || count==13 ||

    count==14)

    x+=100;

    44

  • 7/28/2019 stack n queue using linked list

    45/141

    else if(count==3 || count==4 || count==5 || count==9

    || count==10 || count==11)

    x-=100;

    if(count==3 || count==9)

    {

    x=540;

    y+=60;

    }

    else if(count==6 || count==12)

    {x=340;

    y+=60;

    }

    if(count==15)

    break;

    }

    setlinestyle(0,0,0);

    }

    //------------------------ waiting_for_input( ) ------------

    void Linked_list_Stack ::waiting_for_input( )

    {

    do

    {

    setfillstyle(1,4);

    bar(51,440,99,445);

    setfillstyle(1,10);

    45

  • 7/28/2019 stack n queue using linked list

    46/141

    bar(101,440,149,445);

    setfillstyle(1,1);

    bar(151,440,199,445);

    setfillstyle(1,14);

    bar(201,440,249,445);

    delay(300);

    setfillpattern(fill_pattern,9);

    bar(51,440,99,445);

    delay(150);

    bar(101,440,149,445);delay(150);

    bar(151,440,199,445);

    delay(150);

    bar(201,440,249,445);

    delay(150);

    setfillstyle(1,4);

    bar(51,440,99,445);delay(150);

    setfillstyle(1,10);

    bar(101,440,149,445);

    delay(150);

    setfillstyle(1,1);

    bar(151,440,199,445);

    delay(150);

    setfillstyle(1,14);

    bar(201,440,249,445);

    46

  • 7/28/2019 stack n queue using linked list

    47/141

    }

    while(!kbhit( ));

    setfillpattern(fill_pattern,9);

    bar(51,440,249,445);

    }

    //--------------------------- show_working( ) ------------

    void Linked_list_Stack ::show_working( )

    {

    show_main_screen( );

    delay(1000);show_output_screen( );

    char ch;

    do

    {

    waiting_for_input( );

    ch=getch( );

    switch(ch)

    {

    case 'p': push( );

    break;

    case 'P': push( );

    break;

    case 'o': pop( );

    break;

    case 'O': pop( );

    47

  • 7/28/2019 stack n queue using linked list

    48/141

    break;

    case 'e': delay(500);

    cleardevice();

    ch=27;

    break;

    case 'E': delay(500);

    cleardevice();

    ch=27;

    }

    }

    while(int(ch)!=27);

    delay(500);

    }

    //-----------------------------------------------------------

    class Double_Ended_Linked_list_as_Queue{

    private:

    char fill_pattern[8];

    int inserted_element_count;

    struct node

    {

    long data;

    node *next;

    node *previous;

    };

    48

  • 7/28/2019 stack n queue using linked list

    49/141

    node *rear;

    node *entry;

    node *print;

    node *front;

    public:

    Double_Ended_Linked_list_as_Queue( );

    long get_element( );

    void Delete( );

    void Insert( );

    void print_linked_list( );void show_working( );

    void show_main_screen( );

    void waiting_for_input( );

    void show_element_screen(int);

    void clear_element_screen(int);

    void show_insert_delete_screen(int);

    void show_output_screen( );

    void show_window(int,int,int,int);};

    //--------------------- FUNCTION DEFINITIONS --------------

    //-------------- Double_Ended_Linked_list_as_Queue ( )

    Double_Ended_Linked_list_as_Queue::Double_Ended_Linked_list_as_

    Queue ( )

    {

    rear=NULL;

    front=NULL;

    inserted_element_count=0;

    49

  • 7/28/2019 stack n queue using linked list

    50/141

    fill_pattern[0]=0xAA;

    fill_pattern[1]=0x55;

    fill_pattern[2]=0xAA;

    fill_pattern[3]=0x55;

    fill_pattern[4]=0xAA;

    fill_pattern[5]=0x55;

    fill_pattern[6]=0xAA;

    fill_pattern[7]=0x55;

    }

    //-------------------- show_window(int,int,int,int) --------

    void Double_Ended_Linked_list_as_Queue::show_window(int x_1,int y_1,int x_2,int y_2)

    {

    setcolor(15);

    rectangle(x_1,y_1,x_2,y_2);

    rectangle(x_1+1,y_1+1,x_2-1,y_2-1);

    setcolor(7);

    rectangle(x_1+2,y_1+2,x_2-2,y_2-2);rectangle(x_1+3,y_1+3,x_2-3,y_2-3);

    rectangle(x_1+4,y_1+4,x_2-4,y_2-4);

    setcolor(8);

    rectangle(x_1+5,y_1+5,x_2-5,y_2-5);

    rectangle(x_1+6,y_1+6,x_2-6,y_2-6);

    rectangle(x_1+7,y_1+7,x_2-7,y_2-7);

    }

    //---------------------- show_main_screen( ) -------------

    void Double_Ended_Linked_list_as_Queue::show_main_screen( )

    {

    50

  • 7/28/2019 stack n queue using linked list

    51/141

    cleardevice( );

    setcolor(15);

    setlinestyle(1,0,3);

    rectangle(5,5,getmaxx( )-5,getmaxy( )-5);

    setlinestyle(0,0,0);

    show_window(5,5,getmaxx( )-5,80);

    setfillpattern(fill_pattern,4);

    bar(13,13,getmaxx( )-13,72);

    settextstyle(2,0,7);

    setcolor(0);

    outtextxy(18,17,"Implementation of");

    outtextxy(18,16,"Implementation of");

    setcolor(12);

    outtextxy(19,15,"Implementation of");

    outtextxy(20,15,"Implementation of");

    settextstyle(2,0,9);

    setcolor(0);

    outtextxy(37,37,"Double Ended Linked List as Queue");outtextxy(38,37,"Double Ended Linked List as Queue");

    outtextxy(38,36,"Double Ended Linked List as Queue");

    setcolor(14);

    outtextxy(39,35,"Double Ended Linked List as Queue");

    outtextxy(40,35,"Double Ended Linked List as Queue");

    outtextxy(41,35,"Double Ended Linked List as Queue");

    show_window(5,82,305,getmaxy( )-5);

    setfillpattern(fill_pattern,9);

    bar(14,91,296,getmaxy( )-14);

    51

  • 7/28/2019 stack n queue using linked list

    52/141

    setcolor(6);

    setfillstyle(1,6);

    pieslice(215,105,0,360,10);

    setcolor(2);

    setfillstyle(1,2);

    pieslice(245,105,0,360,10);

    setcolor(4);

    setfillstyle(1,4);

    pieslice(275,105,0,360,10);

    setcolor(7);circle(215,105,11);

    circle(245,105,11);

    circle(275,105,11);

    show_window(307,82,getmaxx( )-5,getmaxy( )-5);

    settextstyle(7,0,4);

    setcolor(0);outtextxy(16,111,"Press:");

    setcolor(10);

    outtextxy(17,110,"Press:");

    outtextxy(18,110,"Press:");

    settextstyle(2,0,6);

    setcolor(0);

    outtextxy(59,151," to Insert an Element");

    outtextxy(59,171," to Delete an Element");

    outtextxy(59,191," to Exit");

    setcolor(14);

    52

  • 7/28/2019 stack n queue using linked list

    53/141

    outtextxy(60,150," to Insert an Element");

    outtextxy(61,150," to Insert an Element");

    outtextxy(60,170," to Delete an Element");

    outtextxy(61,170," to Delete an Element");

    outtextxy(60,190," to Exit");

    outtextxy(61,190," to Exit");

    setfillstyle(2,1);

    bar(317,92,getmaxx( )-15,getmaxy( )-15);

    }

    //--------------------- show_output_screen( ) ------------

    void Double_Ended_Linked_list_as_Queue::show_output_screen( )

    {

    for(int count=0;count

  • 7/28/2019 stack n queue using linked list

    54/141

    setfillstyle(1,6);

    bar(414,420,600,422);

    bar(560,440,622,442);

    setcolor(15);

    setlinestyle(0,0,3);

    rectangle(330,405,400,435);

    setfillstyle(1,9);

    bar(346,406,384,434);

    setfillstyle(1,1);

    bar(331,406,344,434);bar(386,406,399,434);

    setcolor(15);

    setlinestyle(0,0,3);

    rectangle(345,405,385,435);

    setcolor(7);

    setlinestyle(0,0,0);line(337,420,337,460); //Entry->Previous pointing arrow

    line(337,460,415,460);

    line(412,457,415,460);

    line(412,463,415,460);

    line(360,428,360,450); /* Entry->Data pointing arrow */

    line(360,450,415,450);

    line(412,447,415,450);

    line(412,453,415,450);

    line(393,420,393,440); /* Entry->Next pointing arrow */

    54

  • 7/28/2019 stack n queue using linked list

    55/141

    line(393,440,415,440);

    line(412,437,415,440);

    line(412,443,415,440);

    setcolor(15);

    setfillstyle(1,15);

    pieslice(337,420,0,360,2);

    pieslice(393,420,0,360,2);

    settextstyle(0,0,1);

    setcolor(15);

    outtextxy(320,402,"*");

    setcolor(9);

    settextstyle(2,0,4);

    outtextxy(420,454,"Entry->Previous (x=NULL)");

    outtextxy(420,442,"Entry->Data");

    outtextxy(420,430,"Entry->Next (x=NULL)");

    setcolor(11);settextstyle(0,0,1);

    outtextxy(350,417,"0000");

    }

    //--------------------- show_insert_delete_screen(int) -----

    void Double_Ended_Linked_list_as_Queue::

    show_insert_delete_screen(int

    NORMAL_WARNING)

    {

    int x_1;

    int x_2;

    int y_1;

    int y_2;

    55

  • 7/28/2019 stack n queue using linked list

    56/141

    if(NORMAL_WARNING==NORMAL)

    {

    x_1=20;

    x_2=280;

    y_1=277;

    y_2=350;

    }

    if(NORMAL_WARNING==WARNING)

    {

    x_1=20;

    x_2=280;y_1=277;

    y_2=367;

    }

    setcolor(15);

    setlinestyle(1,0,3);

    rectangle(x_1,y_1,x_2,y_2);

    setlinestyle(0,0,0);

    setcolor(15);

    rectangle(x_1,y_1,x_2,y_2);

    setcolor(7);

    rectangle(x_1+1,y_1+1,x_2-1,y_2-1);

    setcolor(8);

    rectangle(x_1+2,y_1+2,x_2-2,y_2-2);

    setfillstyle(1,9);

    bar(x_1+3,y_1+3,x_2-3,y_2-3);

    56

  • 7/28/2019 stack n queue using linked list

    57/141

    }

    //---------------------- show_element_screen(int) ---------

    void Double_Ended_Linked_list_as_Queue::

    show_element_screen(int

    INSERT_DELETE)

    {

    show_insert_delete_screen(NORMAL);

    if(INSERT_DELETE==INSERT)

    {

    settextstyle(2,0,6);setcolor(0);

    outtextxy(28,281,"Enter the Element :");

    setcolor(11);

    outtextxy(29,280,"Enter the Element :");

    outtextxy(30,280,"Enter the Element :");

    }

    else if(INSERT_DELETE==DELETE)

    {

    settextstyle(2,0,6);

    setcolor(0);

    outtextxy(28,281,"Poped Element is :");

    setcolor(11);

    outtextxy(29,280,"Poped Element is :");

    outtextxy(30,280,"Poped Element is :");

    }

    delay(300);

    57

  • 7/28/2019 stack n queue using linked list

    58/141

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    59/141

    arc(180+count,318,270,90,13);

    delay(4);

    }

    }

    //------------------- clear_element_screen(int) -----------

    void Double_Ended_Linked_list_as_Queue::

    clear_element_screen(int

    NORMAL_WARNING)

    {

    if(NORMAL_WARNING==WARNING)

    {for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    60/141

    }

    //---------------------------- get_element( ) ------------

    long Double_Ended_Linked_list_as_Queue::get_element( )

    {

    show_element_screen(INSERT);

    int count=0;

    char string[6]={'\0'};

    do

    {int key_code=0;

    char key=NULL;

    if(kbhit( ))

    key=getch( );

    key_code=int(key);

    if(key_code>=48 && key_code0)

    {

    setfillstyle(1,0);

    bar(130,306,230,330);

    count--;

    60

  • 7/28/2019 stack n queue using linked list

    61/141

    string[count]='\0';

    }

    else if(key_code==13 && count>0)

    break;

    setcolor(12);

    settextstyle(2,0,7);

    moveto(140,305);

    outtext(string);

    moveto(141,305);outtext(string);

    int x=getx( );

    int y=305;

    while(!kbhit( ))

    {

    settextstyle(2,0,7);setcolor(12);

    moveto(x+2,y);

    outtext("_");

    delay(250);

    setcolor(0);

    moveto(x+2,y);

    outtext("_");

    delay(200);

    }

    }

    61

  • 7/28/2019 stack n queue using linked list

    62/141

    while(count

  • 7/28/2019 stack n queue using linked list

    63/141

    {

    setcolor(10);

    setfillstyle(1,10);

    pieslice(245,105,0,360,10);

    sound(1500);

    delay(800);

    nosound( );

    setcolor(2);

    setfillstyle(1,2);

    pieslice(245,105,0,360,10);

    }

    if(inserted_element_count==15)

    {

    setcolor(12);

    setfillstyle(1,12);

    pieslice(275,105,0,360,10);

    sound(2500);delay(1000);

    nosound( );

    setcolor(4);

    setfillstyle(1,4);

    pieslice(275,105,0,360,10);

    delay(200);

    }

    entry=new(node);

    entry->next=NULL;

    entry->previous=NULL;

    63

  • 7/28/2019 stack n queue using linked list

    64/141

    if(inserted_element_count==15)

    {

    show_insert_delete_screen(WARNING);

    settextstyle(7,0,4);

    setcolor(0);

    outtextxy(25,277,"Error:");

    outtextxy(26,277,"Error:");

    setcolor(14);

    outtextxy(27,275,"Error:");

    outtextxy(28,275,"Error:");

    while(!kbhit( ))

    {

    settextstyle(2,0,8);

    setcolor(0);

    outtextxy(46,309,"Not enough heap");

    outtextxy(47,309,"Not enough heap");

    outtextxy(28,335,"space on Screen.");

    outtextxy(29,335,"space on Screen.");

    setcolor(12);

    outtextxy(48,308,"Not enough heap");

    outtextxy(49,308,"Not enough heap");

    outtextxy(50,308,"Not enough heap");

    outtextxy(30,334,"space on Screen.");

    outtextxy(31,334,"space on Screen.");

    outtextxy(32,334,"space on Screen.");

    delay(500);

    64

  • 7/28/2019 stack n queue using linked list

    65/141

    setfillstyle(1,9);

    bar(23,315,277,362);

    delay(400);

    }

    getch( );

    clear_element_screen(1);

    }

    else if(rear==NULL)

    {entry->data=num;

    rear=entry;

    front=rear;

    rear->next=NULL;

    rear->previous=NULL;

    inserted_element_count++;

    }

    else

    {

    entry->data=num;

    rear->next=entry;

    entry->previous=rear;

    rear=entry;

    rear->next=NULL;

    inserted_element_count++;

    }

    print_linked_list( );

    65

  • 7/28/2019 stack n queue using linked list

    66/141

    }

    //---------------------------- Delete( ) ------------------

    void Double_Ended_Linked_list_as_Queue::Delete( )

    {

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    67/141

    delay(200);

    }

    else if(inserted_element_count>0)

    {

    setcolor(10);

    setfillstyle(1,10);

    pieslice(245,105,0,360,10);

    sound(3000);

    delay(800);

    nosound( );

    setcolor(2);

    setfillstyle(1,2);

    pieslice(245,105,0,360,10);

    }

    if(front==NULL)

    {

    show_insert_delete_screen(WARNING);

    settextstyle(7,0,4);

    setcolor(0);

    outtextxy(25,277,"Error:");

    outtextxy(26,277,"Error:");

    setcolor(14);

    outtextxy(27,275,"Error:");

    outtextxy(28,275,"Error:");

    while(!kbhit( ))

    {

    settextstyle(6,0,4);

    67

  • 7/28/2019 stack n queue using linked list

    68/141

    setcolor(0);

    outtextxy(48,306,"Nothing to Pop");

    outtextxy(49,306,"Nothing to Pop");

    setcolor(12);

    outtextxy(50,305,"Nothing to Pop");

    outtextxy(51,305,"Nothing to Pop");

    outtextxy(52,305,"Nothing to Pop");

    delay(500);

    setfillstyle(1,9);

    bar(23,315,277,350);

    delay(400);

    }

    getch( );

    }

    else

    {node *deleted_element;

    long poped_data=front->data;

    deleted_element=front;

    front=front->next;

    front->previous=NULL;

    delete(deleted_element);

    inserted_element_count--;

    char element[6]={'\0'};

    68

  • 7/28/2019 stack n queue using linked list

    69/141

    ltoa(poped_data,element,10);

    show_element_screen(DELETE);

    setcolor(12);

    settextstyle(2,0,7);

    outtextxy(140,305,element);

    outtextxy(141,305,element);

    delay(2500);

    }

    clear_element_screen(DELETE);print_linked_list( );

    }

    //------------------------- print_linked_list( ) ----------

    void Double_Ended_Linked_list_as_Queue::print_linked_list( )

    {

    int count=0;

    int x=335;int y=100;

    print=front;

    setfillstyle(1,0);

    bar(317,92,getmaxx( )-15,getmaxy( )-80);

    while(print!=NULL)

    {

    setcolor(15);

    setlinestyle(0,0,3);

    rectangle(x,y,x+70,y+30);

    69

  • 7/28/2019 stack n queue using linked list

    70/141

    setfillstyle(1,1);

    bar(x+1,y+1,x+14,y+29);

    setfillstyle(1,9);

    bar(x+16,y+1,x+54,y+29);

    setfillstyle(1,1);

    bar(x+56,y+1,x+69,y+29);

    rectangle(x+15,y,x+55,y+30);

    char element[6]={'\0'};

    ltoa(print->data,element,10);

    settextstyle(0,0,1);

    setcolor(11);

    outtextxy(x+20,y+10,element);

    if(count==0 || count==1 || count==2 || count==6 ||

    count==7 || count==8 || count==12 || count==13 ||count==14)

    {

    if(count==0)

    {

    setcolor(15);

    outtextxy(x+4,y+11,"x");

    }

    if(count==inserted_element_count-1)

    {

    setcolor(15);

    rectangle(x+15,y,x+55,y+30);

    outtextxy(x+60,y+11,"x");

    70

  • 7/28/2019 stack n queue using linked list

    71/141

    }

    }

    else

    {

    if(count==inserted_element_count-1)

    {

    setcolor(15);

    rectangle(x+15,y,x+55,y+30);

    outtextxy(x+4,y+11,"x");

    }

    }

    if(count==1 || count==2 || count==7 || count==8 ||

    count==13 || count==14){

    setcolor(7);

    setlinestyle(0,0,3);

    line(x-40,y+10,x-2,y+10);

    line(x-6,y+6,x-2,y+10);

    line(x-6,y+14,x-2,y+10);

    line(x-28,y+20,x+7,y+20);

    line(x-28,y+20,x-24,y+16);

    line(x-28,y+20,x-24,y+24);

    setcolor(15);

    setfillstyle(1,15);

    pieslice(x-37,y+10,0,360,2);

    pieslice(x+7,y+20,0,360,2);

    }

    else if(count==4 || count==5 || count==10 ||

    count==11)

    {

    71

  • 7/28/2019 stack n queue using linked list

    72/141

    setcolor(7);

    setlinestyle(0,0,3);

    line(x+64,y+10,x+98,y+10);

    line(x+94,y+6,x+98,y+10);

    line(x+94,y+14,x+98,y+10);

    line(x+72,y+20,x+107,y+20);

    line(x+72,y+20,x+76,y+16);

    line(x+72,y+20,x+76,y+24);

    setcolor(15);setfillstyle(1,15);

    pieslice(x+63,y+10,0,360,2);

    pieslice(x+107,y+20,0,360,2);

    }

    else if(count==3 || count==9)

    {

    setcolor(7);setlinestyle(0,0,3);

    line(x+60,y-50,x+80,y-50);

    line(x+80,y-50,x+80,y+20);

    line(x+72,y+20,x+80,y+20);

    line(x+72,y+20,x+76,y+16);

    line(x+72,y+20,x+76,y+24);

    line(x+63,y-30,x+63,y+10);

    line(x+63,y-28,x+59,y-24);

    line(x+63,y-28,x+67,y-24);

    72

  • 7/28/2019 stack n queue using linked list

    73/141

    setcolor(15);

    setfillstyle(1,15);

    pieslice(x+63,y+10,0,360,2);

    pieslice(x+63,y-50,0,360,2);

    }

    else if(count==6 || count==12)

    {

    setcolor(7);

    setlinestyle(0,0,3);

    line(x-15,y-50,x+10,y-50);

    line(x-15,y-50,x-15,y+20);

    line(x-15,y+20,x,y+20);

    line(x-2,y+20,x-6,y+16);

    line(x-2,y+20,x-6,y+24);

    line(x+7,y-30,x+7,y+10);

    line(x+3,y-24,x+7,y-28);

    line(x+11,y-24,x+7,y-28);

    setcolor(15);

    setfillstyle(1,15);

    pieslice(x+7,y+10,0,360,2);

    pieslice(x+7,y-50,0,360,2);

    }

    setcolor(7);

    setlinestyle(0,0,3);

    line(360,125,360,138); /* Front Arrow */

    line(356,134,360,138);

    line(364,134,360,138);

    setcolor(14);

    73

  • 7/28/2019 stack n queue using linked list

    74/141

    settextstyle(2,0,4);

    outtextxy(338,140,"front");

    if(count==inserted_element_count-1)

    {

    setcolor(7);

    setlinestyle(0,0,3);

    line(x+40,y+25,x+40,y+38);

    line(x+36,y+34,x+40,y+38);

    line(x+44,y+34,x+40,y+38);

    setcolor(14);

    settextstyle(2,0,4);outtextxy(x+38,y+40,"rear");

    }

    print=print->next;

    count++;

    if(count==0 || count==1 || count==2 || count==6 ||

    count==7 || count==8 || count==12 || count==13 ||

    count==14)x+=100;

    else if(count==3 || count==4 || count==5 || count==9

    || count==10 || count==11)

    x-=100;

    if(count==3 || count==9)

    {

    x=535;

    y+=60;

    }

    else if(count==6 || count==12)

    {

    x=335;

    74

  • 7/28/2019 stack n queue using linked list

    75/141

    y+=60;

    }

    if(count==15)

    break;

    }

    setlinestyle(0,0,0);

    }

    //------------------------ waiting_for_input( ) -----------

    void Double_Ended_Linked_list_as_Queue::waiting_for_input( )

    {do

    {

    setfillstyle(1,4);

    bar(51,440,99,445);

    setfillstyle(1,10);

    bar(101,440,149,445);

    setfillstyle(1,11);

    bar(151,440,199,445);

    setfillstyle(1,14);

    bar(201,440,249,445);

    delay(300);

    setfillpattern(fill_pattern,9);

    bar(51,440,99,445);

    delay(150);

    75

  • 7/28/2019 stack n queue using linked list

    76/141

    bar(101,440,149,445);

    delay(150);

    bar(151,440,199,445);

    delay(150);

    bar(201,440,249,445);

    delay(150);

    setfillstyle(1,4);

    bar(51,440,99,445);

    delay(150);

    setfillstyle(1,10);

    bar(101,440,149,445);

    delay(150);

    setfillstyle(1,11);bar(151,440,199,445);

    delay(150);

    setfillstyle(1,14);

    bar(201,440,249,445);

    }

    while(!kbhit( ));

    setfillpattern(fill_pattern,9);

    bar(51,440,249,445);

    }

    //--------------------------- show_working( ) -------------

    void Double_Ended_Linked_list_as_Queue::show_working( )

    {

    show_main_screen( );

    delay(1000);

    show_output_screen( );

    char ch;

    int selected=0;

    do

    76

  • 7/28/2019 stack n queue using linked list

    77/141

    {

    waiting_for_input( );

    ch=getch( );

    switch(ch)

    {

    case 'i': Insert( );

    break;

    case 'I': Insert( );

    break;

    case 'd': Delete( );

    break;

    case 'D': Delete( );

    break;

    case 'e': selected=1;

    break;

    case 'E': selected=1;break;

    }

    }

    while(!selected && int(ch)!=27);

    delay(500);

    }

    //------------------------------------------------------------

    //---------------------- CLASS DEFINITION -----------------

    class Linked_list_Queue

    77

  • 7/28/2019 stack n queue using linked list

    78/141

    {

    private:

    char fill_pattern[8];

    int inserted_element_count;

    struct node

    {

    long data;

    node *next;

    };

    node *rear;node *entry;

    node *print;

    node *front;

    public:

    Linked_list_Queue( );

    long get_element( );

    void Delete( );

    void Insert( );

    void print_linked_list( );

    void show_working( );

    void show_main_screen( );

    void waiting_for_input( );

    void show_element_screen(int);

    void clear_element_screen(int);

    void show_linked_list_screen( );

    void show_output_screen(int);

    void show_window(int,int,int,int);

    };

    78

  • 7/28/2019 stack n queue using linked list

    79/141

    //--------------------- FUNCTION DEFINITIONS --------------

    //---------------------- Linked_list_Queue( ) -------------

    Linked_list_Queue::Linked_list_Queue ( )

    {

    rear=NULL;

    front=NULL;

    inserted_element_count=0;

    fill_pattern[0]=0xAA;

    fill_pattern[1]=0x55;

    fill_pattern[2]=0xAA;

    fill_pattern[3]=0x55;

    fill_pattern[4]=0xAA;

    fill_pattern[5]=0x55;

    fill_pattern[6]=0xAA;fill_pattern[7]=0x55;

    }

    //-------------------- show_window(int,int,int,int) -------

    void Linked_list_Queue::show_window(int x_1,int y_1,int x_2,int

    y_2)

    {

    setcolor(15);

    rectangle(x_1,y_1,x_2,y_2);

    rectangle(x_1+1,y_1+1,x_2-1,y_2-1);

    79

  • 7/28/2019 stack n queue using linked list

    80/141

    setcolor(7);

    rectangle(x_1+2,y_1+2,x_2-2,y_2-2);

    rectangle(x_1+3,y_1+3,x_2-3,y_2-3);

    rectangle(x_1+4,y_1+4,x_2-4,y_2-4);

    setcolor(8);

    rectangle(x_1+5,y_1+5,x_2-5,y_2-5);

    rectangle(x_1+6,y_1+6,x_2-6,y_2-6);

    rectangle(x_1+7,y_1+7,x_2-7,y_2-7);

    }

    //---------------------- show_main_screen( ) --------------

    void Linked_list_Queue ::show_main_screen( ){

    setcolor(15);

    setlinestyle(1,0,3);

    rectangle(5,5,getmaxx( )-5,getmaxy( )-5);

    setlinestyle(0,0,0);

    show_window(5,5,getmaxx( )-5,80);

    setfillpattern(fill_pattern,4);

    bar(13,13,getmaxx( )-13,72);

    settextstyle(3,0,4);

    setcolor(0);

    outtextxy(17,22,"Implementation of Linked List as Queue");

    outtextxy(18,22,"Implementation of Linked List as

    Queue");

    setcolor(14);

    outtextxy(19,20,"Implementation of Linked List as Queue");

    80

  • 7/28/2019 stack n queue using linked list

    81/141

    outtextxy(20,20,"Implementation of Linked List as

    Queue");

    outtextxy(21,20,"Implementation of Linked List as

    Queue");

    show_window(5,82,305,getmaxy( )-5);

    setfillpattern(fill_pattern,9);

    bar(14,91,296,getmaxy( )-14);

    setcolor(6);

    setfillstyle(1,6);

    pieslice(215,105,0,360,10);

    setcolor(2);

    setfillstyle(1,2);

    pieslice(245,105,0,360,10);

    setcolor(4);

    setfillstyle(1,4);

    pieslice(275,105,0,360,10);

    setcolor(7);

    circle(215,105,11);

    circle(245,105,11);

    circle(275,105,11);

    show_window(307,82,getmaxx( )-5,getmaxy( )-5);

    settextstyle(7,0,4);

    setcolor(0);

    outtextxy(16,111,"Press:");

    setcolor(10);

    81

  • 7/28/2019 stack n queue using linked list

    82/141

    outtextxy(17,110,"Press:");

    outtextxy(18,110,"Press:");

    settextstyle(2,0,6);

    setcolor(0);

    outtextxy(59,151," to Insert an Element");

    outtextxy(59,171," to Delete an Element");

    outtextxy(59,191," to Exit");

    setcolor(14);

    outtextxy(60,150," to Insert an Element");

    outtextxy(61,150," to Insert an Element");

    outtextxy(60,170," to Delete an Element");

    outtextxy(61,170," to Delete an Element");

    outtextxy(60,190," to Exit");

    outtextxy(61,190," to Exit");

    setfillstyle(2,1);

    bar(317,92,getmaxx( )-15,getmaxy( )-15);}

    //--------------------- show_linked_list_screen( ) ---------

    void Linked_list_Queue::show_linked_list_screen( )

    {

    for(int count=0;count

  • 7/28/2019 stack n queue using linked list

    83/141

    }

    setcolor(12);

    settextstyle(2,0,7);

    outtextxy(405,400,"Linked List (Queue)");

    outtextxy(406,400,"Linked List (Queue)");

    outtextxy(407,400,"Linked List (Queue)");

    setfillstyle(1,6);

    bar(402,420,618,422);

    setcolor(15);

    setlinestyle(0,0,3);

    rectangle(330,405,390,435);

    setfillstyle(1,9);

    bar(331,406,374,434);

    setfillstyle(1,1);

    bar(376,406,389,434);

    line(375,405,375,435);

    setcolor(7);

    setlinestyle(0,0,0);

    line(352,425,352,455); /* Entry->Data pointing arrow */

    line(352,455,415,455);

    line(412,452,415,455);

    line(412,458,415,455);

    line(382,423,382,443); /* Entry->Next pointing arrow */

    line(382,443,415,443);

    line(412,440,415,443);

    83

  • 7/28/2019 stack n queue using linked list

    84/141

    line(412,446,415,443);

    setfillstyle(1,15);

    pieslice(382,420,0,360,2);

    settextstyle(0,0,1);

    setcolor(15);

    outtextxy(320,402,"*");

    setcolor(9);

    outtextxy(420,452,"Entry->Data");

    outtextxy(420,438,"Entry->Next (x=NULL)");

    setcolor(11);

    outtextxy(333,417,"00000");

    }

    //----------------------- show_output_screen(int) ---------

    Void Linked_list_Queue::show_output_screen(int NORMAL_WARNING){

    int x_1;

    int x_2;

    int y_1;

    int y_2;

    if(NORMAL_WARNING==NORMAL)

    {

    x_1=20;

    x_2=280;

    y_1=277;

    y_2=350;

    }

    if(NORMAL_WARNING==WARNING)

    84

  • 7/28/2019 stack n queue using linked list

    85/141

    {

    x_1=20;

    x_2=280;

    y_1=277;

    y_2=367;

    }

    setcolor(15);

    setlinestyle(1,0,3);

    rectangle(x_1,y_1,x_2,y_2);

    setlinestyle(0,0,0);

    setcolor(15);rectangle(x_1,y_1,x_2,y_2);

    setcolor(7);

    rectangle(x_1+1,y_1+1,x_2-1,y_2-1);

    setcolor(8);

    rectangle(x_1+2,y_1+2,x_2-2,y_2-2);

    setfillstyle(1,9);

    bar(x_1+3,y_1+3,x_2-3,y_2-3);

    }

    //---------------------- show_element_screen(int) ---------

    Void Linked_list_Queue::show_element_screen(int INSERT_DELETE)

    {

    show_output_screen(NORMAL);

    if(INSERT_DELETE==INSERT)

    {

    settextstyle(2,0,6);

    setcolor(0);

    outtextxy(28,281,"Enter the Element :");

    85

  • 7/28/2019 stack n queue using linked list

    86/141

    setcolor(11);

    outtextxy(29,280,"Enter the Element :");

    outtextxy(30,280,"Enter the Element :");

    }

    else if(INSERT_DELETE==DELETE)

    {

    settextstyle(2,0,6);

    setcolor(0);

    outtextxy(28,281,"Deleted Element is :");

    setcolor(11);outtextxy(29,280,"Deleted Element is :");

    outtextxy(30,280,"Deleted Element is :");

    }

    delay(300);

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    87/141

    arc(180-count,318,90,270,14);

    line(180-count,303,180+count,303);

    line(180-count,304,180+count,304);

    line(180-count,333,180+count,333);

    line(180-count,332,180+count,332);

    arc(180+count,318,270,90,15);

    arc(180+count,318,270,90,14);

    setcolor(8);

    line(180-count,305,180+count,305);line(180-count,331,180+count,331);

    arc(180-count,318,90,270,13);

    arc(180+count,318,270,90,13);

    delay(4);

    }

    }//------------------- clear_element_screen(int) -----------

    Void Linked_list_Queue::clear_element_screen(int NORMAL_WARNING)

    {

    if(NORMAL_WARNING==WARNING)

    {

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    88/141

    }

    }

    else if(NORMAL_WARNING==NORMAL)

    {

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    89/141

    if(key_code>=48 && key_code0)

    {

    setfillstyle(1,0);

    bar(130,306,230,330);

    count--;

    string[count]='\0';

    }

    else if(key_code==13 && count>0)

    break;

    setcolor(12);

    settextstyle(2,0,7);

    moveto(140,305);outtext(string);

    moveto(141,305);

    outtext(string);

    int x=getx( );

    int y=305;

    while(!kbhit( ))

    {

    settextstyle(2,0,7);

    setcolor(12);

    moveto(x+2,y);

    89

  • 7/28/2019 stack n queue using linked list

    90/141

    outtext("_");

    delay(250);

    setcolor(0);

    moveto(x+2,y);

    outtext("_");

    delay(200);

    }

    }

    while(count

  • 7/28/2019 stack n queue using linked list

    91/141

    if(inserted_element_count

  • 7/28/2019 stack n queue using linked list

    92/141

    {

    show_output_screen(WARNING);

    settextstyle(7,0,4);

    setcolor(0);

    outtextxy(25,277,"Error:");

    outtextxy(26,277,"Error:");

    setcolor(14);

    outtextxy(27,275,"Error:");

    outtextxy(28,275,"Error:");

    while(!kbhit( )){

    settextstyle(2,0,8);

    setcolor(0);

    outtextxy(46,309,"Not enough heap");

    outtextxy(47,309,"Not enough heap");

    outtextxy(28,335,"space on Screen.");

    outtextxy(29,335,"space on Screen.");

    setcolor(12);

    outtextxy(48,308,"Not enough heap");

    outtextxy(49,308,"Not enough heap");

    outtextxy(50,308,"Not enough heap");

    outtextxy(30,334,"space on Screen.");

    outtextxy(31,334,"space on Screen.");

    outtextxy(32,334,"space on Screen.");

    delay(500);

    setfillstyle(1,9);

    bar(23,315,277,362);

    delay(400);

    92

  • 7/28/2019 stack n queue using linked list

    93/141

    }

    getch( );

    clear_element_screen(1);

    }

    else if(rear==NULL)

    {

    entry->data=num;

    entry->next=NULL;

    rear=entry;

    front=rear;

    inserted_element_count++;}

    else

    {

    entry->data=num;

    entry->next=NULL;

    rear->next=entry;

    rear=entry;

    inserted_element_count++;}

    print_linked_list( );

    }

    //--------------------------- Delete( ) -------------------

    void Linked_list_Queue::Delete( )

    {

    for(int count=1;count

  • 7/28/2019 stack n queue using linked list

    94/141

    setcolor(6);

    setfillstyle(1,6);

    pieslice(215,105,0,360,10);

    delay(300);

    }

    if(inserted_element_count==0)

    {

    setcolor(12);

    setfillstyle(1,12);

    pieslice(275,105,0,360,10);

    sound(2500);

    delay(1000);nosound( );

    setcolor(4);

    setfillstyle(1,4);

    pieslice(275,105,0,360,10);

    delay(200);

    }

    else if(inserted_element_count>0){

    setcolor(10);

    setfillstyle(1,10);

    pieslice(245,105,0,360,10);

    sound(3000);

    delay(800);

    nosound( );

    setcolor(2);

    setfillstyle(1,2);

    pieslice(245,105,0,360,10);

    }

    94

  • 7/28/2019 stack n queue using linked list

    95/141

    if(front==NULL)

    {

    show_output_screen(WARNING);

    settextstyle(7,0,4);

    setcolor(0);

    outtextxy(25,277,"Error:");

    outtextxy(26,277,"Error:");

    setcolor(14);

    outtextxy(27,275,"Error:");

    outtextxy(28,275,"Error:");

    while(!kbhit( ))

    {

    settextstyle(6,0,4);

    setcolor(0);

    outtextxy(48,306,"Nothing to Delete");

    outtextxy(49,306,"Nothing to Delete");

    setcolor(12);

    outtextxy(50,305,"Nothing to Delete");outtextxy(51,305,"Nothing to Delete");

    outtextxy(52,305,"Nothing to Delete");

    delay(500);

    setfillstyle(1,9);

    bar(23,315,277,350);

    delay(400);

    }

    getch( );

    }

    else

    {

    long Deleted_element=front->data;

    node *temp;

    95

  • 7/28/2019 stack n queue using linked list

    96/141

    temp=front;

    front=front->next;

    inserted_element_count--;

    delete (temp);

    char element[6]={'\0'};

    ltoa(Deleted_element,element,10);

    show_element_screen(DELETE);

    setcolor(12);

    settextstyle(2,0,7);

    outtextxy(140,305,element);

    outtextxy(141,305,element);

    delay(2500);

    }clear_element_screen(DELETE);

    print_linked_list( );

    }

    //----------------------- print_linked_list( ) ------------

    void Linked_list_Queue::print_linked_list( )

    {

    int count=0;int x=340;

    int y=100;

    print=front;

    setfillstyle(1,0);

    bar(317,92,getmaxx( )-15,getmaxy( )-80);

    while(print!=NULL)

    {

    setcolor(15);

    setlinestyle(0,0,3);

    rectangle(x,y,x+60,y+30);

    char element[6]={'\0'};

    ltoa(print->data,element,10);

    96

  • 7/28/2019 stack n queue using linked list

    97/141

    if(count==0 || count==1 || count==2 || count==6 ||

    count==7 || count==8 || count==12 || count==13 ||

    count==14)

    {

    setfillstyle(1,9);

    bar(x+1,y+1,x+44,y+29);

    setfillstyle(1,1);

    bar(x+46,y+1,x+59,y+29);

    setcolor(15);

    line(x+45,y,x+45,y+30);

    setcolor(11);

    settextstyle(0,0,1);

    outtextxy(x+3,y+10,element);

    if(count==inserted_element_count-1)

    {

    setcolor(15);

    outtextxy(x+50,y+11,"x");}

    }

    else

    {

    setfillstyle(1,9);

    bar(x+16,y+1,x+59,y+29);

    setfillstyle(1,1);

    bar(x+1,y+1,x+14,y+29);

    setcolor(15);

    line(x+15,y,x+15,y+30);

    setcolor(11);

    settextstyle(0,0,1);

    outtextxy(x+18,y+10,element);

    97

  • 7/28/2019 stack n queue using linked list

    98/141

    if(count==inserted_element_count-1)

    {

    setcolor(15);

    outtextxy(x+4,y+11,"x");

    }

    }

    if(count==1 || count==2 || count==7 || count==8 ||

    count==13 || count==14)

    {

    setcolor(15);

    line(x-45,y+15,x,y+15);

    setfillstyle(1,15);pieslice(x-47,y+15,0,360,2);

    line(x-6,y+11,x-2,y+15);

    line(x-6,y+19,x-2,y+15);

    }

    else if(count==4 || count==5 || count==10 ||

    count==11)

    {

    setcolor(15);line(x+60,y+15,x+105,y+15);

    setfillstyle(1,15);

    pieslice(x+107,y+15,0,360,2);

    line(x+66,y+11,x+62,y+15);

    line(x+66,y+19,x+62,y+15);

    }

    else if(count==3 || count==9)

    {

    setcolor(15);

    setfillstyle(1,15);

    pieslice(x+53,y-45,0,360,2);

    98

  • 7/28/2019 stack n queue using linked list

    99/141

    setlinestyle(0,0,3);

    line(x+55,y-45,x+75,y-45);

    line(x+75,y-45,x+75,y+15);

    line(x+60,y+15,x+75,y+15);

    line(x+62,y+15,x+66,y+11);

    line(x+62,y+15,x+66,y+19);

    }

    else if(count==6 || count==12)

    {

    setcolor(15);setfillstyle(1,15);

    pieslice(x+7,y-45,0,360,2);

    setlinestyle(0,0,3);

    line(x-15,y-45,x+10,y-45);

    line(x-15,y-45,x-15,y+15);

    line(x-15,y+15,x,y+15);

    line(x-2,y+15,x-6,y+11);

    line(x-2,y+15,x-6,y+19);

    }

    setcolor(7);

    setlinestyle(0,0,3);

    line(350,125,350,138); /* Bottom Arrow */

    line(346,134,350,138);

    line(354,134,350,138);

    setcolor(14);

    settextstyle(2,0,4);

    outtextxy(332,140,"Front");

    99

  • 7/28/2019 stack n queue using linked list

    100/141

    if(count==inserted_element_count-1)

    {

    setcolor(7);

    setlinestyle(0,0,3);

    line(x+30,y+25,x+30,y+38);

    line(x+26,y+34,x+30,y+38);

    line(x+34,y+34,x+30,y+38);

    setcolor(14);

    settextstyle(2,0,4);

    outtextxy(x+30,y+40,"Rear");

    }

    print=print->next;count++;

    if(count==0 || count==1 || count==2 || count==6 || count==7

    || count==8 || count==12 || count==13 || count==14)

    x+=100;

    else if(count==3 || count==4 || count==5 || count==9

    || count==10 || count==11)

    x-=100;

    if(count==3 || count==9){

    x=540;

    y+=60;

    }

    else if(count==6 || count==12)

    {

    x=340;

    y+=60;

    }

    if(count==15)

    break;

    }

    100

  • 7/28/2019 stack n queue using linked list

    101/141

    setlinestyle(0,0,0);

    }

    //------------------------ waiting_for_input( ) -----------

    void Linked_list_Queue ::waiting_for_input( )

    {

    do

    {

    setfillstyle(1,4);

    bar(51,440,99,445);

    setfillstyle(1,10);

    bar(101,440,149,445);

    setfillstyle(1,1);bar(151,440,199,445);

    setfillstyle(1,14);

    bar(201,440,249,445);

    delay(300);

    setfillpattern(fill_pattern,9);

    bar(51,440,99,445);

    delay(150);

    bar(101,440,149,445);delay(150);

    bar(151,440,199,445);

    delay(150);

    bar(201,440,249,445);

    delay(150);

    setfillstyle(1,4);

    bar(51,440,99,445);

    delay(150);

    setfillstyle(1,10);

    bar(101,440,149,445);

    delay(150);

    setfillstyle(1,1);

    101

  • 7/28/2019 stack n queue using linked list

    102/141

    bar(151,440,199,445);

    delay(150);

    setfillstyle(1,14);

    bar(201,440,249,445);

    }

    while(!kbhit( ));

    setfillpattern(fill_pattern,9);

    bar(51,440,249,445);

    }

    //--------------------------- show_working( ) -------------

    void Linked_list_Queue ::show_working( )

    {show_main_screen( );

    delay(1000);

    show_linked_list_screen( );

    char ch;

    do

    {

    waiting_for_input( );

    ch=getch( );switch(ch)

    {

    case 'i': Insert( );

    break;

    case 'I': Insert( );

    break;

    case 'd': Delete( );

    break;

    case 'D': Delete( );

    break;

    102

  • 7/28/2019 stack n queue using linked list

    103/141

    case 'e': delay(500);

    cleardevice();

    ch=27;

    case 'E': delay(500);

    cleardevice();

    ch=27;

    }

    } while((int)ch!=27);

    }

    class skstack{ private:

    struct stack

    {

    int top;

    int items[size];

    char s2[STSIZE];

    }s;

    struct node{

    int info;

    struct node *next;

    }*top;

    typedef struct node *NODEPTR;

    NODEPTR s1;

    public:

    void lpush(NODEPTR *,int);

    void ldisplay(NODEPTR *);

    void ldisplay1(NODEPTR *);

    int empty1(NODEPTR *);

    int empty(struct stack *);

    103

  • 7/28/2019 stack n queue using linked list

    104/141

    char stacktop(struct stack *);

    void lpop(NODEPTR *);

    void button(int,int,int,int,char[]);

    void buttonon(int,int,int,int);

    void buttonoff(int,int,int,int);

    void closebyslash();

    void closebyslash1();

    void stack(void);

    void push(struct stack *,int);

    int pop(struct stack *);

    void display(struct stack *);

    void display1(struct stack *);

    void rdisplay(struct stack *);void esolve();

    void call();

    void edisplay(struct stack *);

    void edisplay1(struct stack *);

    void gotorc(int,int);

    void dis(int,int);

    void closebyline();

    void push1(struct stack *,char);char pop1(struct stack *);

    void display2(struct stack *);

    void linklist();

    NODEPTR getnode();

    void freenode(NODEPTR);

    }sk;

    //Fourth window for select the Implementation & Application

    void screen1(int c)

    {

    int n,d;

    while(1)

    {

    switch(c)

    104

  • 7/28/2019 stack n queue using linked list

    105/141

    {

    case 1 : setbkcolor(BLUE);

    cleardevice();

    settextstyle(1,0,3);

    outtextxy(160,50," IMPLIMENTATION OF LINKED LIST");

    setcolor(GREEN);

    outtextxy(140,110,"1 : LINKED LIST AS STACK");

    outtextxy(140,150,"2 : LINKED LIST AS QUEUE");

    outtextxy(140,190,"3 : Double Ended LINKED LIST

    AS STACK");

    outtextxy(140,230,"4 : Double Ended LINKED LIST

    AS QUEUE");

    outtextxy(140,270,"5 : EXIT");setcolor(4);

    settextstyle(7,0,2);

    outtextxy(180,350,"ENTER THE CHOICE. . .");

    cin>>n;

    switch(n)

    {

    case 1 :

    Linked_list_Stack obj0;obj0.show_working( );

    break;

    case 2 :

    Linked_list_Queue obj;

    obj.show_working( );

    break;

    case 3 :

    Double_ended_Linked_list_as_Stack obj1;

    obj1.show_working( );

    break;

    case 4 :

    Double_Ended_Linked_list_as_Queue obj2;

    obj2.show_working( );

    105

  • 7/28/2019 stack n queue using linked list

    106/141

    break;

    case 5 : cleardevice();

    screen();

    break;

    default:

    outtextxy(160,370,"Enter Number Between 1 to 5");

    delay(1000);

    cleardevice();

    }

    break;

    case 3 : cleardevice();

    setcolor(YELLOW);

    settextstyle(8,0,6);setbkcolor(6);

    outtextxy(150,200,"THANK YOU");

    delay(2000);

    exit(1);

    break;

    }

    }

    }/* thied window in button is used */

    void screen()

    {

    settextstyle(3,0,4);

    setcolor(YELLOW);

    setbkcolor(7);

    outtextxy(90,30,"IMPLEMENTATION ");

    outtextxy(210,80," OF LINKED LIST");

    setcolor(7);

    settextstyle(1,0,2);

    sk.button(190,150,230,50," IMPLIMENTATION");

    sk.buttonon(190,150,230,50);

    sk.button(250,350,100,50," EXIT");

    106

  • 7/28/2019 stack n queue using linked list

    107/141

    int no=0,but=1;

    while(no==0)

    {

    no=getch();

    switch(no)

    {

    case 80 :

    no=0;

    switch(but)

    {

    case 3:

    sk.buttonoff(250,350,100,50);//3but=1;

    break;

    case 2:

    sk.buttonon(250,350,100,50);//3

    but=3;

    break;

    case 1:

    sk.buttonoff(190,150,230,50);//1but=2;

    break;

    }

    break;

    case 72 :

    no=0;

    switch(but)

    {

    case 1:

    sk.buttonoff(190,150,230,50);//1

    sk.buttonon(250,350,100,50);//3

    but=3;

    break;

    107

  • 7/28/2019 stack n queue using linked list

    108/141

    case 2:

    sk.buttonon(190,150,230,50);//1

    but=1;

    break;

    case 3:

    sk.buttonoff(250,350,100,50);//3

    but=2;

    break;

    }

    break;

    case 13 : no=but;

    }

    }sk.closebyslash();

    screen1(no);

    }

    void main()

    {

    int gd=DETECT,gm,x,y,c;

    initgraph(&gd,&gm,"..\\bgi");

    x=getmaxx();y=getmaxy();

    /* first window */

    rectangle(0,0,x,y);

    setcolor(GREEN);

    settextstyle(7,0,8);

    outtextxy(130,50,"WELLCOME");

    outtextxy(230,170,"TO");

    outtextxy(160,280,"PROJECT");

    delay(2500);

    sk.closebyline();

    setcolor(GREEN);

    /* second window */

    rectangle(0,0,getmaxx(),getmaxy());

    108

  • 7/28/2019 stack n queue using linked list

    109/141

    setcolor(RED);

    settextstyle(1,0,6);

    outtextxy(160,30,"PROJECT BY");

    setcolor(YELLOW);

    settextstyle(1,0,4);

    outtextxy(150,140,"MR.Avinash Kumar Sinha");

    setcolor(GREEN);

    settextstyle(1,0,4);

    outtextxy(120,230,"UNDER GUIDENCE OF");

    outtextxy(200,270,"MRS. Shivangi Patil");

    settextstyle(3,0,5);

    setcolor(6);

    outtextxy(300,350,"FROM");setcolor(6);

    outtextxy(400,400,"MCA(I)");

    delay(3000);

    cleardevice();

    setbkcolor(7);

    settextstyle(1,0,2);

    textcolor(3);

    screen();getch();

    restorecrtmode();

    closegraph();

    }

    /* standered operation of stack */

    void skstack::stack(void)

    {

    int p,z,n,temp;

    char a[10];

    s.top=-1;

    rectangle(0,0,getmaxx(),getmaxy());

    do

    {

    109

  • 7/28/2019 stack n queue using linked list

    110/141

    sk.gotorc(1,2);

    cout

  • 7/28/2019 stack n queue using linked list

    111/141

    5.2 INPUT AND OUTPUT DESIGNS

    SCREEN DESIGN

    WELCOME WINDOW

    111

  • 7/28/2019 stack n queue using linked list

    112/141

    112

  • 7/28/2019 stack n queue using linked list

    113/141

    113

  • 7/28/2019 stack n queue using linked list

    114/141

    114

  • 7/28/2019 stack n queue using linked list

    115/141

    115

  • 7/28/2019 stack n queue using linked list

    116/141

    116

  • 7/28/2019 stack n queue using linked list

    117/141

    117

  • 7/28/2019 stack n queue using linked list

    118/141

    118

  • 7/28/2019 stack n queue using linked list

    119/141

    119

  • 7/28/2019 stack n queue using linked list

    120/141

    120

  • 7/28/2019 stack n queue using linked list

    121/141

    121

  • 7/28/2019 stack n queue using linked list

    122/141

    122

  • 7/28/2019 stack n queue using linked list

    123/141

    123

  • 7/28/2019 stack n queue using linked list

    124/141

    124

  • 7/28/2019 stack n queue using linked list

    125/141

    125

  • 7/28/2019 stack n queue using linked list

    126/141

    126

  • 7/28/2019 stack n queue using linked list

    127/141

    127

  • 7/28/2019 stack n queue using linked list

    128/141

    128

  • 7/28/2019 stack n queue using linked list

    129/141

    129

  • 7/28/2019 stack n queue using linked list

    130/141

    130

  • 7/28/2019 stack n queue using linked list

    131/141

    131

  • 7/28/2019 stack n queue using linked list

    132/141

    132

  • 7/28/2019 stack n queue using linked list

    133/141

    133

  • 7/28/2019 stack n queue using linked list

    134/141

    134

  • 7/28/2019 stack n queue using linked list

    135/141

    135

  • 7/28/2019 stack n queue using linked list

    136/141

    136

    Chapter No.6

    User Manual

  • 7/28/2019 stack n queue using linked list

    137/141

    User manual

    How to use application?

    Step1:First run .exe file of the application. After running .exe file you will see the

    welcome screen and developer screen one after another.

    Step2:

    Now press any key to continue. After pressing the key current window will close

    and you will see menu of the of the application.

    Step3:

    To select any method of the application click left mouse button on that particular

    button and if you want get an help of that particular method click right mouse button of

    that button.

    Step4:

    After performing particular method press any key to go back to the menu.

    Step5:

    Click on the exit button to get an exit from the application.

    137

  • 7/28/2019 stack n queue using linked list

    138/141

    138

    Chapter No.7

    CONCLUSIONS

  • 7/28/2019 stack n queue using linked list

    139/141

    7.1 Scope

    1. It can be useful for performing stack and queue using linked list.

    2. This application is simple to use and easy to understand.

    3. It enables user to easily understand complicated diagrams.

    4. Use of switch cases makes it user friendly.

    7.2 Limitations

    1. The system can done only two types of linked list like stack & queue.2. User can not enter elements more than 10 . System will restricted user to input

    only 10 elements so that animation can be well fitted to screen and resolution.

    3. The system is purely based on graphical interface and will not maintaining any

    files that can be used for storing purpose.

    There are few limits otherwise; the system is satisfactory, easilyunderstandable and attractive one.

    139

  • 7/28/2019 stack n queue using linked list

    140/141

    140

    Chapter No. 8

    Bibliography

  • 7/28/2019 stack n queue using linked list

    141/141

    Bibliography

    Advanced Graphics Programming Programming Using C/C++.

    C++ Complete Reference Herbert Schildt

    Object Oriented Programming with C++ - E. Balgurusami

    TURBOC3 HELPS MENU.