Question: Reverse Linked List Your task is to build a linked list, and then reverse the list. You can build the list anywhere you desire (inside

Reverse Linked List

Your task is to build a linked list, and then reverse the list. You can build the list anywhere you desire (inside main, a separate function, or even separate files). Use the struct given in the template for your nodes . Do not use the following libraries: algorithm, cmath Input Space separated integers Output Print out the reversed linked list with space between each element. End the output on a new line.

#include

struct Node { int val; Node * next; };

Node * reverseList( Node * head ){ // Try to implement an iterative and recursive version }

int main(){

// Create the linked list ( doesn't have to be in main, if you want to make another function you can ).

// Call reverseList() on the list. // Print out the contents of the list return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!