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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started