SlideShare ist ein Scribd-Unternehmen logo
1 von 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();

}

Weitere ähnliche Inhalte

Was ist angesagt?

Linked list
Linked listLinked list
Linked listKumar
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked ListSayantan Sur
 
Double linked list
Double linked listDouble linked list
Double linked listraviahuja11
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular listiCreateWorld
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1Balaji Thala
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
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 9096308941
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
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...Chad Petrovay
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of listElavarasi K
 

Was ist angesagt? (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
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie C program to perform operations on doubly linked list

DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
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.pdffathimafancyjeweller
 
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.pdfamrishinda
 
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)Ankit Gupta
 
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.pdfanujmkt
 
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.pdfMAYANKBANSAL1981
 
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.docxGordonpACKellyb
 
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.pdfmeerobertsonheyde608
 
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.pdfARYAN20071
 
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.pdfanushkaent7
 
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.pdfAnkitchhabra28
 
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.pdferremmfab
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
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.pdfconnellalykshamesb60
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxVeerannaKotagi1
 

Ähnlich wie C program to perform operations on doubly linked list (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
 

Mehr von 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
 

Kürzlich hochgeladen

Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 

Kürzlich hochgeladen (20)

Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 

C program to perform operations on doubly linked list

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