0% found this document useful (0 votes)
3 views

expt6 manual sheets

The document outlines a C programming experiment focused on implementing a doubly linked list with operations for creating, inserting, displaying, and searching for data items. The objective is to enhance understanding of data structures, pointer manipulation, and modular programming. Key functionalities include adding nodes at the start and end, traversing the list, and ensuring efficient searching in both directions within an ordered list of integers.

Uploaded by

onlyfansfile
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

expt6 manual sheets

The document outlines a C programming experiment focused on implementing a doubly linked list with operations for creating, inserting, displaying, and searching for data items. The objective is to enhance understanding of data structures, pointer manipulation, and modular programming. Key functionalities include adding nodes at the start and end, traversing the list, and ensuring efficient searching in both directions within an ordered list of integers.

Uploaded by

onlyfansfile
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment 6

Program Statement:
Develop and execute a program in C using suitable data structures to perform searching for a
data item in an ordered list of items in both directions. The program should implement the
following operations:

a. Create a doubly linked list by adding each node at the start.

b. Insert a new node at the end of the list.

c. Display the content of the list.

Consider an integer number as a data item.

Objective of the experiment:


1. To provide solid understanding of doubly linked list.
2. To provide understanding of usage of pointer to manipulate linked list.
3. To introduce modular programming in C.

Theory:
Doubly linked list:
A doubly linked list is a type of linked list where each node contains a data element and two
pointers, one pointing to the next node in the sequence and another pointing to the previous node.
This bidirectional linking allows for easy traversal in both forward and backward directions. The
structure of a doubly linked list node is as follows:

struct Node

int info; // Data element of the node

struct Node* next; // Pointer to the next node in the sequence

struct Node* prev; // Pointer to the previous node in the sequence

};
Searching in an Ordered List:
Searching in an ordered list involves locating a specific data item within the list. In the context of
a doubly linked list, searching can be performed efficiently in both directions—forward and
backward. The list is assumed to be ordered, meaning the elements are arranged in ascending or
descending order based on the data. If the list is not ordered, we sort the list to be in a particular
order

a. Create a Doubly Linked List by Adding Each Node at the Start:


To create a doubly linked list by adding each node at the start, new nodes are inserted at the
beginning of the list. This operation involves adjusting the pointers of the newly added node, the
previous head, and, if necessary, the tail of the list.

b. Insert a New Node at the End of the List:


Inserting a new node at the end of the list requires updating the pointers of the current tail node,
the new node, and adjusting any relevant pointers to maintain the integrity of the doubly linked
list.

c. Display the Content of the List:


Displaying the content of the list involves traversing the list in either direction and printing the
data element of each node. This operation provides a visual representation of the ordered list.

Consider an Integer Number as a Data Item:


In this implementation, the data item stored in each node is an integer number. The choice of
using integers simplifies the implementation and makes it easier to demonstrate the functionality
of searching in an ordered list. The program utilizes various operations, such as creating the list,
inserting nodes, and displaying the contents, to ensure the effective organization and retrieval of
integer data within the doubly linked list.

Overall Objective:
The overarching goal of developing and executing a program with these specifications is to
showcase the efficiency of searching in both directions within an ordered doubly linked list. By
implementing operations like insertion at the start and end, the program demonstrates the
flexibility and utility of doubly linked lists in maintaining ordered data and performing searches
with improved time complexity.

Important instructions for writing program:


Function declarations:
// Function to create a doubly linked list by adding each node at the start
void insertAtFront():
// Function to insert a new node at the end of the list
void insertAtEnd();

// Function to display the content of the list


void traverse();

// Function for searching in the ordered list in both directions


void search();

//Function to sort the list elements


void sortList();

skeleton of main function:

int main() {
//Local declaration
do {
printf("1. Create a doubly linked list and insert at front 2. Insert a new node at the end 3.
Display the list 4. Search in the list 5. Sort list 6. Exit");
//read choice from user
switch (choice)
{
case 1: // Function call for creating a linked list and inserting a node at front
break;
case 2:// Function call to insert data at the end of the list
break;
case 3:// Function call to display linked list
break;
------

case 6:
default:
printf("Invalid choice. Please enter a valid option. ");
} // end switch
} while (choice != 6);
}//end main

Algorithm of important modules:


Implementation details of important modules:

Application of the program implemented:

Output:

You might also like