SlideShare a Scribd company logo
1 of 10
/* Write a C program that uses functions to perform the following operations on doubly linked list.:

            i) Creation ii) Insertion iii) Deletion iv) Traversal in both ways

*/



#include "stdio.h"

#include "alloc.h"



typedef struct dubll

{

int data;

struct dubll *leftlink,*rightlink;

}*DUBLL;



DUBLL high,temp_node,low,last,pntr;

int flag=0;



DUBLL NodeAlloc();

DUBLL Search(int,int);



void CreateItem();

void AppendItem();

void PrintItem();

void DeleteItem();

DUBLL Search(int item,int flag);
DUBLL NodeAlloc();

void InsertItem();



void main(void)

{

int choice,Item;

high=NULL;

while(1)

{

    clrscr();

    printf("n ttt***** M A I N M E N U *****nn");

 printf("n 1: Create Linked List n 2: Append a Node to the List n 3: Traverse the List n 4: Delete a
Node from the List n 5: Search a Node n 6: Insert a Node to the List n 7: Close nntt Enter your
Option [ ]bb");

    scanf("%d",&choice);

    switch(choice)

    {

        case 1:

           CreateItem();

           puts("nPress any key to go back to main menu.");

              getch();

           break;

        case 2:

           AppendItem();

           break;
case 3:

       PrintItem();

   puts("nPress any key to go back to main menu.");

   getch();

       break;

case 4:

   DeleteItem();

   break;

case 5:

   printf("Find an Item: ");

   scanf("%d",&Item);

   temp_node=Search(Item,0);

   if(temp_node)

   {

           puts("The item is available in the Linked List.");

   }

   else

       {

   puts("The item is not found in the Linked List.");

   }

   getch();

           break;

case 6:

   InsertItem();
break;

        case 7:

           exit();

        default:

             puts("Invalid choice.");

             puts("nPress any key to go back to main menu.");

                   getch();

             break;

    }

    }

}



/* Function to Create the list*/

void CreateItem()

{

    if(high==NULL)

    {

        printf("n --Creating the list--");

        temp_node=NodeAlloc();

        printf("n Enter starting data (as integer value) :");

        scanf("%d",&temp_node->data);

        high=temp_node;

    }

    else{ printf("n List already created @ %d with %d as data.",high,high->data);}
}



/* Function to Append items to the list*/

void AppendItem()

{

    low=high;

    if(high==NULL)

    {

        CreateItem();

    }

    else

    {

        temp_node=NodeAlloc();

        printf("n Enter Item (in integer) :");

        scanf("%d",&temp_node->data);

        temp_node->rightlink=NULL;



        while(low->rightlink!=NULL)

        low=low->rightlink;

        low->rightlink=temp_node;

        temp_node->leftlink=low;

        last=low->rightlink;



    }
}



/* Function to Traverse the list both ways and print the data*/

void PrintItem()

{

    DUBLL temp_node;

    if(high==NULL)

    {

        printf("n List is not available. Please create a list first.");

        getch();

        CreateItem();

    }

    temp_node=high;

    last=low->rightlink;

    printf("n--Printing The List In Forward direction--n");



    while(temp_node!=NULL)                    //In forward direction

              {

                  printf("t %d",temp_node->data);

                  temp_node = temp_node->rightlink;

              }

    printf("n");

    printf("n--Printing The List In Backward direction--n");

              temp_node=high;
if(temp_node->rightlink==NULL){printf("%d",temp_node->data);return; }

               while(last!=NULL)                 //In backward direction

               {

                   printf("t %d",last->data);

                   last = last->leftlink;

                }

}



/* Function to Delete items of the list*/

void DeleteItem()

{

int value;

DUBLL temp_node;

if(high==NULL)

{

    printf("n List is not available. Please create a list first.");

    getch();

    CreateItem();

}

printf("n Item to delete :");

scanf("%d",&value);

pntr=Search(value,1);

pntr->leftlink->rightlink=pntr->rightlink;

pntr->rightlink->leftlink=pntr->leftlink;
temp_node=pntr;

free(temp_node);

}



/* Function to Search an item from the list*/

DUBLL Search(int item,int flag)

{

    temp_node = high;

    if(high==NULL)

    {

        printf("n List is not available. Please create a list first.");

        getch();

        CreateItem();

    }

    while(temp_node!=NULL)

    {

    if(temp_node->data==item )

    {

        if(flag==0)

        {

            return(1);

        }

        else

        {
return(temp_node);

        }

     }

     temp_node=temp_node->rightlink;

    }

}



/* Function to Allocate nodes*/

DUBLL NodeAlloc()

{

    DUBLL tmep_node;

    tmep_node=malloc(sizeof(struct dubll));

    if(tmep_node==NULL)

        {

         printf("n No memory available. Node allocation cannot be done.");

        }

        tmep_node->rightlink=tmep_node->leftlink=NULL;

    return(tmep_node);

}



/* Function to Insert items in the middle of the list*/

void InsertItem()

{

    int node;
DUBLL temp_node;



    if(high==NULL)

    {

        printf("n List is not available. Please create a list first.");

        getch();

        CreateItem();

    }

    temp_node=NodeAlloc();

    printf("Position At which node to be inserted: ___ & New Item Value: ___ ");

    scanf("%d",&node);

    scanf("%d",&temp_node->data);

    pntr=Search(node,1);



    if(pntr->rightlink==NULL){printf("n The operation is not possible."); getch();return;}

        temp_node->leftlink=pntr;                 //creating link to new node

        temp_node->rightlink=pntr->rightlink;



        pntr->rightlink->leftlink=temp_node;

        pntr->rightlink=temp_node;



        printf("n Item has been Inserted.");

        getch();

}

More Related Content

What's hot

Linked list
Linked listLinked list
Linked list
Kumar
 

What's hot (20)

Linked list
Linked listLinked list
Linked list
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
 
week-16x
week-16xweek-16x
week-16x
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
Examples sandhiya class'
Examples sandhiya class'Examples sandhiya class'
Examples sandhiya class'
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Array list
Array listArray list
Array list
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Binary tree
Binary treeBinary tree
Binary tree
 
Advanced Crystal Reports: Techniques for compiling Annual Reports & other sta...
Advanced Crystal Reports: Techniques for compiling Annual Reports & other sta...Advanced Crystal Reports: Techniques for compiling Annual Reports & other sta...
Advanced Crystal Reports: Techniques for compiling Annual Reports & other sta...
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Git avançado
Git avançadoGit avançado
Git avançado
 
Functional php
Functional phpFunctional php
Functional php
 
Tugas1
Tugas1Tugas1
Tugas1
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 

Viewers also liked (6)

kerala psc ayurveda medial officer 2012
kerala psc ayurveda medial officer 2012kerala psc ayurveda medial officer 2012
kerala psc ayurveda medial officer 2012
 
Ay psc 147 2005
Ay psc 147 2005Ay psc 147 2005
Ay psc 147 2005
 
Kerala psc sa previous exam solved papers
Kerala psc sa previous exam solved papersKerala psc sa previous exam solved papers
Kerala psc sa previous exam solved papers
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
ch6
ch6ch6
ch6
 

Similar to week-14x

DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
mustkeem khan
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
amrishinda
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
MAYANKBANSAL1981
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
GordonpACKellyb
 
My C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfMy C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdf
meerobertsonheyde608
 
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfBINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
ARYAN20071
 
The Program to find out the middle of a given linked listclass Lin.pdf
The Program to find out the middle of a given linked listclass Lin.pdfThe Program to find out the middle of a given linked listclass Lin.pdf
The Program to find out the middle of a given linked listclass Lin.pdf
anushkaent7
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
Ankitchhabra28
 
create a binary search tree from an empty one by adding the key valu.pdf
create a binary search tree from an empty one by adding the key valu.pdfcreate a binary search tree from an empty one by adding the key valu.pdf
create a binary search tree from an empty one by adding the key valu.pdf
erremmfab
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
vasavim9
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
connellalykshamesb60
 

Similar to week-14x (20)

DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
Linked lists
Linked listsLinked lists
Linked lists
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
 
Programs
ProgramsPrograms
Programs
 
My C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfMy C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdf
 
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfBINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
 
The Program to find out the middle of a given linked listclass Lin.pdf
The Program to find out the middle of a given linked listclass Lin.pdfThe Program to find out the middle of a given linked listclass Lin.pdf
The Program to find out the middle of a given linked listclass Lin.pdf
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
week-19x
week-19xweek-19x
week-19x
 
create a binary search tree from an empty one by adding the key valu.pdf
create a binary search tree from an empty one by adding the key valu.pdfcreate a binary search tree from an empty one by adding the key valu.pdf
create a binary search tree from an empty one by adding the key valu.pdf
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
 

More from KITE www.kitecolleges.com (20)

week-11x
week-11xweek-11x
week-11x
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 
week-10x
week-10xweek-10x
week-10x
 
week-1x
week-1xweek-1x
week-1x
 
week-18x
week-18xweek-18x
week-18x
 
ch14
ch14ch14
ch14
 
ch16
ch16ch16
ch16
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-22x
week-22xweek-22x
week-22x
 
week-5x
week-5xweek-5x
week-5x
 
week-6x
week-6xweek-6x
week-6x
 
week-3x
week-3xweek-3x
week-3x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch17
ch17ch17
ch17
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-4x
week-4xweek-4x
week-4x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

week-14x

  • 1. /* Write a C program that uses functions to perform the following operations on doubly linked list.: i) Creation ii) Insertion iii) Deletion iv) Traversal in both ways */ #include "stdio.h" #include "alloc.h" typedef struct dubll { int data; struct dubll *leftlink,*rightlink; }*DUBLL; DUBLL high,temp_node,low,last,pntr; int flag=0; DUBLL NodeAlloc(); DUBLL Search(int,int); void CreateItem(); void AppendItem(); void PrintItem(); void DeleteItem(); DUBLL Search(int item,int flag);
  • 2. DUBLL NodeAlloc(); void InsertItem(); void main(void) { int choice,Item; high=NULL; while(1) { clrscr(); printf("n ttt***** M A I N M E N U *****nn"); printf("n 1: Create Linked List n 2: Append a Node to the List n 3: Traverse the List n 4: Delete a Node from the List n 5: Search a Node n 6: Insert a Node to the List n 7: Close nntt Enter your Option [ ]bb"); scanf("%d",&choice); switch(choice) { case 1: CreateItem(); puts("nPress any key to go back to main menu."); getch(); break; case 2: AppendItem(); break;
  • 3. case 3: PrintItem(); puts("nPress any key to go back to main menu."); getch(); break; case 4: DeleteItem(); break; case 5: printf("Find an Item: "); scanf("%d",&Item); temp_node=Search(Item,0); if(temp_node) { puts("The item is available in the Linked List."); } else { puts("The item is not found in the Linked List."); } getch(); break; case 6: InsertItem();
  • 4. break; case 7: exit(); default: puts("Invalid choice."); puts("nPress any key to go back to main menu."); getch(); break; } } } /* Function to Create the list*/ void CreateItem() { if(high==NULL) { printf("n --Creating the list--"); temp_node=NodeAlloc(); printf("n Enter starting data (as integer value) :"); scanf("%d",&temp_node->data); high=temp_node; } else{ printf("n List already created @ %d with %d as data.",high,high->data);}
  • 5. } /* Function to Append items to the list*/ void AppendItem() { low=high; if(high==NULL) { CreateItem(); } else { temp_node=NodeAlloc(); printf("n Enter Item (in integer) :"); scanf("%d",&temp_node->data); temp_node->rightlink=NULL; while(low->rightlink!=NULL) low=low->rightlink; low->rightlink=temp_node; temp_node->leftlink=low; last=low->rightlink; }
  • 6. } /* Function to Traverse the list both ways and print the data*/ void PrintItem() { DUBLL temp_node; if(high==NULL) { printf("n List is not available. Please create a list first."); getch(); CreateItem(); } temp_node=high; last=low->rightlink; printf("n--Printing The List In Forward direction--n"); while(temp_node!=NULL) //In forward direction { printf("t %d",temp_node->data); temp_node = temp_node->rightlink; } printf("n"); printf("n--Printing The List In Backward direction--n"); temp_node=high;
  • 7. if(temp_node->rightlink==NULL){printf("%d",temp_node->data);return; } while(last!=NULL) //In backward direction { printf("t %d",last->data); last = last->leftlink; } } /* Function to Delete items of the list*/ void DeleteItem() { int value; DUBLL temp_node; if(high==NULL) { printf("n List is not available. Please create a list first."); getch(); CreateItem(); } printf("n Item to delete :"); scanf("%d",&value); pntr=Search(value,1); pntr->leftlink->rightlink=pntr->rightlink; pntr->rightlink->leftlink=pntr->leftlink;
  • 8. temp_node=pntr; free(temp_node); } /* Function to Search an item from the list*/ DUBLL Search(int item,int flag) { temp_node = high; if(high==NULL) { printf("n List is not available. Please create a list first."); getch(); CreateItem(); } while(temp_node!=NULL) { if(temp_node->data==item ) { if(flag==0) { return(1); } else {
  • 9. return(temp_node); } } temp_node=temp_node->rightlink; } } /* Function to Allocate nodes*/ DUBLL NodeAlloc() { DUBLL tmep_node; tmep_node=malloc(sizeof(struct dubll)); if(tmep_node==NULL) { printf("n No memory available. Node allocation cannot be done."); } tmep_node->rightlink=tmep_node->leftlink=NULL; return(tmep_node); } /* Function to Insert items in the middle of the list*/ void InsertItem() { int node;
  • 10. DUBLL temp_node; if(high==NULL) { printf("n List is not available. Please create a list first."); getch(); CreateItem(); } temp_node=NodeAlloc(); printf("Position At which node to be inserted: ___ & New Item Value: ___ "); scanf("%d",&node); scanf("%d",&temp_node->data); pntr=Search(node,1); if(pntr->rightlink==NULL){printf("n The operation is not possible."); getch();return;} temp_node->leftlink=pntr; //creating link to new node temp_node->rightlink=pntr->rightlink; pntr->rightlink->leftlink=temp_node; pntr->rightlink=temp_node; printf("n Item has been Inserted."); getch(); }