Exercise 5.1: (3) : Experiment 5 - Singly Linked Lists
Exercise 5.1: (3) : Experiment 5 - Singly Linked Lists
Write a program to display string using linked list. Take a string of character from user and
split the string in character, and then insert each character into linked list.
Example:
String = RPI
h R P I N
ead ULL
Consider a scenario where a firm wants to maintain the data of its employees. The data
containing employee number, name, and salary and department # are saved in a singly linked
list. Create following functions for the employee list.
InsertAtFront: Insertion of a record at the front.
InsertAtEnd: Insertion of a record at the end.
Insert: Insertion of a record at any position in the list
DeleteFirst: Deletion of first record.
DeleteLast: Deletion of last record.
Delete: Deletion of a record at any position in the list.
Search: Searching any record based on employee number and dept no.
Display: Displaying all records.
Exercise 5.3: (3)
Write a program to split a single linked list in two separate lists and display the both lists.
EXPERIMENT 6 DOUBLY LINKED LISTS
1. Objectives:
(a). Understanding the concepts and operations of doubly linked lists
(b). Implement doubly linked list using dynamic structures
2. Time Required: 3 hrs
3. Software Required:
(a). Windows OS
(b). Microsoft Visual Studio 2012
4. Doubly Linked Lists:A doubly linked list is a data structure consisting of a group of nodes which together
represent a sequence and are connected to each other in both directions (Bi-directional). In Doubly linked
list, each node has two pointers. One pointer to its successor (NULL if there is none) and one pointer to its
predecessor (NULL if there is none) which enables bi-directional
Head
traversing.
5. Insertion:To insert data in a doubly linked list, a record is created holding the new item. The next pointer
of the new record is set to link it to the item which is to follow it in the list. The pre-pointer of the new
record is set to link it to the item which is to before it in the list.
6. Deletion: In deletion process, element can be deleted from three different places. When the node is
deleted, the memory allocated to that node is released and the previous and next nodes of that node are
linked.
Exercises:
Exercise 6.1: (4)
Write a menu driven program to perform insertion, deletion and display functions for doubly linked
list.
Exercise 6.2: (6)
Using the Exercise 5.1, write a function MoveToFront( ) with one argument of data type
integer. This function will first search the linked list and compare the Data member of the
node with the given number as argument. If the search finds the number in the list then this
function will move that node to the start of the list as shown in the example below. The order
of the remaining nodes is to remain unchanged. If no node in the list contains the integer,
MoveToFront( ) should leave the list unchanged. Assume that the list contains no duplicate
values. The structure definition of the doubly linked list is
structListNode{
ListNode *pre;
int Data;
ListNode *Next;
}*head;
The function declaration of MoveToFront function is Void MoveToFront(int);
Example:
The two diagrams below illustrate the effect of the call MoveToFront( 5).
Before the call:
Web References:
http://idlebrains.org/tutorials/data-structures-tutorials/doubly-linked-list-tutorial/
http://www.codeproject.com/Articles/668818/Implementing-a-Doubly-Linked-List-to-be-used-on-an
Video Resource:
http://www.youtube.com/watch?v=5s0x8bc9DvQ
http://www.youtube.com/watch?v=JdQeNxWCguQ
Summary:
This lab introduces the concepts of doubly linked list and its implementation using dynamic allocation.