Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Reverse a Linked List - Iterative Method _ Data Structure Tutorials

Rating
-
Sold
-
Pages
1
Uploaded on
22-04-2023
Written in
2022/2023

Reverse a Linked List - Iterative Method _ Data Structure Tutorials

Institution
Course

Content preview

2.8 Reverse a Linked List - Iterative Method | Data
Structure Tutorials
Jenny's Lectures CS IT
In this video we'll use what iterative approach to reverse a linked list using loops and recursion.
In the first video we discuss the method we will apply the method here and after that we will
write down the code see how you can reverse this. After reversing of this linked list the output
should be something like this. Each node is going to contain address of its previous node so we
have to maintain the address of previous node also fine in this case right now previous node is
having zero right so now this link has been broken now fine so now we can not move here
because this link is broken. C in this case also we are going to create three functions one is
create linked list second one is reverse and third one is display the linked list. We have already
discussed the coding of those functions in the previous videos you can check out that we do in
this I button video.
Both current node and next node will contain whatever the value in head in head we have 100
so here hundred and here also hundred so now this is also pointing here and this is pointing to
the first node now we are going to start the traversing till where till here what condition you will
write obviously this means that this next would be zero. Next node is going to store address of
previous node so obviously we have to update the previous node value so now this previous
node should contain hundred. Next node using this next role pointed you can access this node
so next node next is 150 right so here you can write what current node is equal to next node.
Alexis says he has reversed all the links but one thing you have to take care header still pointing
here. Head should contain address of this node that is so from where you can get 300 no
problem we have previous node link and this is containing 300 that is why we are maintaining
this previous node so now after this while loop you can write what head is equal to previous
node.
The code will work even if you have only 1 node if only one node is there that is 5 is there then
output is also 5. value is 300 so now head is pointing here fine so as you can call the display
function fine and the output would be 7 1 6 and 5.

Written for

Course

Document information

Uploaded on
April 22, 2023
Number of pages
1
Written in
2022/2023
Type
SUMMARY

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
pranavnawandar

Also available in package deal

Get to know the seller

Seller avatar
pranavnawandar mahindra university
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
19
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions