Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the new_reverse() function. Reverse a singly linked list in C++, without modifying pointers such as next. You can only modify values of the nodes.

Implement the new_reverse() function. Reverse a singly linked list in C++, without modifying pointers such as "next". You can only modify "values" of the nodes. You are not allowed to use external structures such as arrays or linked lists to perform operations, you have to directly work on the linked list.

image text in transcribed

//Linked List Operations #include //cin and cout using namespace std; class Node { public: int value; Node* next; Node() { next = nullptr; }//default constructor Node(int i) { value = i; next = nullptr; }//constructor }; class LinkedList { public: Node* head; LinkedList() { head = nullptr; } void makeList(int m, int n);//create a linked list of m nodes with //values randomly distrubuted in o..n-1 void printList(); void new_reverse(); //You are only allowed to modify "values" of nodes, but not "next" //You have to directly work on the linked list. You are not allowed to use 1/external structures such as array or linked list to perform operations. void new_sort(); //Sorting -- Only modify pointers (next or temporary pointers). //Changes of values of nodes are not allowed. // You are not allowed to use external structures such as array or linked list //to perform operations and transfer the values back to the linked list. void removeAll(int k);//Remove all nodes with value k void Linkedlist::makelist(int m, int n) { for (int i = 0; inext = head; head = p; void Linkedlist::printList() { Node* p = head; cout value next; } void LinkedList:: new_reverse() { You need to implement this function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

Students also viewed these Databases questions