In this lab we will write code for working with a Linked Lis

In this lab we will write code for working with a Linked List. Node class represents a single element of the linked list. class Node {public: Node(); Node* prev; string key; Node* next;}; LinkedList class represent one entire linked list. class LinkedList {public: LinkedList(); void Insert(string key); void Print(); Node* Find(string key); void Delete(Node* x); Node* head;}; Code to insert strings into linked list. while (true){getline(cin, line); if (line.empty()){break;} l.Insert(line);}

Solution

It has programs to implement a Stack, to implement a Queue, to implement a Doubly Linked List, a Circular Doubly Linked List and a Binary Tree using linked list. Each node in a Doubly Linked List contains two address fields, one field stores the address of the previous node with which it is linked and the other address field stores the address of the next node to be followed. A Circular Doubly Linked List is a doubly-linked-list in which the head element’s previous pointer points to the tail element and tail element’s next pointer points to the head element. A Binary Tree is a group of nodes where each node contains a left reference, a right reference and a data element. The section also contains a C program which demonstrates the operations of a Singly Linked List. In a Singly Linked List, each node has a single link to the other node.

A linked list is a linear data structure where each element is a separate object.

Each element (we will call it a node) of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. The entry point into a linked list is called thehead of the list. It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference.

A linked list is a dynamic data structure. The number of nodes in a list is not fixed and can grow and shrink on demand. Any application which has to deal with an unknown number of objects will need to use a linked list.

One disadvantage of a linked list against an array is that it does not allow direct access to the individual elements. If you want to access a particular item then you have to start at the head and follow the references until you get to that item.

Another disadvantage is that a linked list uses more memory compare with an array - we extra 4 bytes (on 32-bit CPU) to store a reference to the next node.

 In this lab we will write code for working with a Linked List. Node class represents a single element of the linked list. class Node {public: Node(); Node* pre

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site