You are required to write the following functions using this class:
class Doubly_linked_list // Use a class Doubly_linked_list to represent an object { public: // constructor initialize the nextPtr Doubly_linked_list() { prevPtr = 0; // point to null at the beginning nextPtr = 0; // point to null at the beginning } // get a number int GetNum() { return number; } // set a number void SetNum(int num) { number = num; } // get the prev pointer Doubly_linked_list *GetPrev() { return prevPtr; } // set the prev pointer void SetPrev(Doubly_linked_list *ptr) { prevPtr = ptr; } // get the next pointer Doubly_linked_list *GetNext() { return nextPtr; } // set the next pointer void SetNext(Doubly_linked_list *ptr) { nextPtr = ptr; } private: int number; Doubly_linked_list *prevPtr; Doubly_linked_list *nextPtr; };
1 Create a doubly linked list. The integer assigned in a node of the list is its sequence (i.e., 0 is assigned in the first node, 1 is assigned in the second node, and so on.). Remember to assign the previous and next pointers properly.
2 Print a list.
3 Print a list reversely.
4 Insert a node at the front of a list
5 Remove a node from the front of a list
6 Insert a node at the back of a list
7 Remove a node from the back of a list
8 Insert a node before the node with a given value in a list
9 Remove a node with a give value in a list
You should use the following main program to test the above nine functions and do NOT modify the main program:
int main() { int num; Doubly_linked_list *headPtr; Doubly_linked_list *newPtr; cout << "How many items you want to create? "; cin >> num; headPtr = Create_Doubly_linked_list(num); Print_Doubly_linked_list(headPtr); Print_Doubly_linked_list_reversely(headPtr); newPtr = new Doubly_linked_list; newPtr->SetNum(num); cout << "Insert a node at the front of the list:" << endl; headPtr = Insert_node_at_front(newPtr, headPtr); Print_Doubly_linked_list(headPtr); Print_Doubly_linked_list_reversely(headPtr); cout << "Remove a node from the front of the list:" << endl; headPtr = Remove_node_at_front(headPtr); Print_Doubly_linked_list(headPtr); Print_Doubly_linked_list_reversely(headPtr); newPtr = new Doubly_linked_list; newPtr->SetNum(num); cout << "Insert a node at the end of the list:" << endl; headPtr = Insert_node_at_back(newPtr, headPtr); Print_Doubly_linked_list(headPtr); Print_Doubly_linked_list_reversely(headPtr); cout << "Remove a node from the back of the list:" << endl; headPtr = Remove_node_at_back(headPtr); Print_Doubly_linked_list(headPtr); Print_Doubly_linked_list_reversely(headPtr); cout << "Enter the number of a new node: "; cin >> num; newPtr = new Doubly_linked_list; newPtr->SetNum(num); cout << "Choose a number to add a node before the node with such value : "; cin >> num; cout << "Insert a node before the node with the value " << num << " in the list:" << endl; headPtr = Insert_node(num, newPtr, headPtr); Print_Doubly_linked_list(headPtr); Print_Doubly_linked_list_reversely(headPtr); cout << "Choose a number to delete a node with such value : "; cin >> num; cout << "Remove a node with value " << num << " from the list:" << endl; headPtr = Remove_node(num, headPtr); Print_Doubly_linked_list(headPtr); Print_Doubly_linked_list_reversely(headPtr); return 0; }
The sample output should be:
Help me make these 9 c++ functions asap, keep in mind the language should be a beginners level and dont make it complicated so it allows me to understand as a beginner.
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...
The source code I have is what I'm trying to fix for the assignment at the bottom. Source code: //Group 1 - Jodie Butterworth, Brandon Kidd, Matt Heckler //11-21-19 //CSC 201 // Exercise to practice the basic manipulations of a linked list // Note: Uses nullptr, so need to make sure your compiler is set to use C++11 // In Code::Blocks this is under Settings==>Compiler #include <iostream> using namespace std; // Structure to contain data for a node (Could be...
Q) Modify the class Linked List below to make it a Doubly Linked List. Name your class DoublyLinkedList. Add a method addEnd to add an integer at the end of the list and a method displayInReverse to print the list backwards. void addEnd(int x): create this method to add x to the end of the list. void displayInReverse(): create this method to display the list elements from the last item to the first one. Create a main() function to test...
Please answer in C++ Derive a class called Queue from the linked list described in Assignment 2 (list of Dates). This means the Queue class will inherit all the properties (data and functions) of the linked list. But, since a queue allows pushing only at the back and popping at the front of the list, you will need to prevent the addition in the front and removal at the back. To do this, you must derive the Queue class in...
C++ - I have a doubly linked list, but I haven't been able to get the "reverse list" option in the code to work(It's option #in the menu in the program). I received this guidance for testing: Test 4 cases by entering (in this order) c,a,z,k,l,m This tests empty list, head of list, end of list and middle of list. Then delete (in this order) a,z,l. This tests beginning, end and middle deletes. This exhaustively tests for pointer errors. #include...
Please answer in C++. Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions...
C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the sortedList class. Call your new class doublyLinkedList. Convert the baseline code into a doubly linkedlist, and thoroughly test all existing operations (make sure to check all edge conditions), and then implement the new operations below. The class should have the following additional class methods: • A reverse method: this method will reverse the order of the doubly linked list. This method takes no parameters,...
In this assignment, you will implement a sort method on singly-linked and doubly-linked lists. Implement the following sort member function on a singly-linked list: void sort(bool(*comp)(const T &, const T &) = defaultCompare); Implement the following sort member function on a doubly-linked list: void sort(bool(*comp)(const T &, const T &) = defaultCompare); The sort(…) methods take as a parameter a comparator function, having a default assignment of defaultCompare, a static function defined as follows: template <typename T> static bool defaultCompare(const...
Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time complexity is omitted. Any methods/functions below could be changed into something different. I was thinking of changing the method of getting size of list and maybe change from numbers to letters for nodes. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null;...