Double ended linked list C++
Ngày đăng:
21/12/2021
Trả lời:
0
Lượt xem:
28
This C Program implement a doubly linked list & provide insertion, deletion & display operations. Doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes. The beginning and ending nodes previous and next links, respectively, point to some kind of terminator, typically a sentinel node or null, to facilitate traversal of the list. Here we need to preform insertion, deletion and display all the modes of given doubly linked list. Here is source code of the C Program to implement a doubly linked list & provide insertion, deletion & display operations. The C program is successfully compiled and run on a Linux system. The program output is also shown below. /*
* C Program to Implement a Doubly Linked List & provide Insertion, Deletion & Display Operations
*/
#include advertisement $ cc pgm1.c
$ a.out
1 - Insert at beginning
2 - Insert at end
3 - Insert at position i
4 - Delete at i
5 - Display from beginning
6 - Display from end
7 - Search for element
8 - Sort the list
9 - Update an element
10 - Exit
Enter choice : 1
Enter value to node : 10
Enter choice : 2
Enter value to node : 50
Enter choice : 4
Enter position to be deleted : 1
Node deleted
Enter choice : 1
Enter value to node : 34
Enter choice : 3
Enter position to be inserted : 2
Enter value to node : 13
Enter choice : 4
Enter position to be deleted : 4
Error : Position out of range to delete
Enter choice : 1
Enter value to node : 15
Enter choice : 1
Enter value to node : 67
Enter choice : 3
Enter position to be inserted : 2
Enter value to node : 34
Enter choice : 4
Enter position to be deleted : 3
Node deleted
Enter choice : 7
Enter value to search : 15
Error : 15 not found in list
Enter choice : 8
Linked list elements from begining : 13 34 34 50 67
Enter choice : 9
Enter node data to be updated : 45
Enter new data : 89
Error : 45 not found in list to update
Enter choice : 9
Enter node data to be updated : 50
Enter new data : 90
Enter choice : 5
Linked list elements from begining : 13 34 34 90 67
Enter choice : 6
Reverse order of linked list is : 67 90 34 34 13
Enter choice : 7
Enter value to search : 90
Data found in 4 position
Enter choice : 8
Linked list elements from begining : 13 34 34 67 90
Enter choice : 7
Enter value to search : 90
Data found in 5 position
Enter choice : 9
Enter node data to be updated : 34
Enter new data : 56
Linked list elements from begining : 13 56 34 67 90
Enter choice : 10 Sanfoundry Global Education & Learning Series 1000 C Programs. advertisement advertisement Heres the list of Best Reference Books in C Programming, Data-Structures and Algorithms If you wish to look at other example programs on Linked List, go to C Programming Examples on Linked List. If you wish to look at programming examples on all topics, go to C Programming Examples. « Prev - C Program to Traverse the Tree Non-Recursively » Next - C Program to Search an Element in a Tree Recursively |