SlideShare una empresa de Scribd logo
1 de 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();

}

Más contenido relacionado

La actualidad más candente

Linked list
Linked listLinked list
Linked list
Kumar
 

La actualidad más candente (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
 

Destacado (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 a 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 a 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
 

Más de 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
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
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
 

Último (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).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...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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
 
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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
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.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

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(); }