Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

How many pointers are required to reverse a link list?

Answers were Sorted based on User's Feedback

How many pointers are required to reverse a link list?..

Using 3 pointers:
curr, next, result pointers, curr points to current node,
next obviously points to the next node, result points to

{
struct node* result = NULL;
struct node* next;
while (current != NULL)
{
next = current->next; // tricky: note the next node
current->next = result; // move the node onto the result
result = current;
current = next;
}
}

 Is This Answer Correct ? 14 Yes 1 No

How many pointers are required to reverse a link list?..

You cannot must have a pointer to a pointer if you want to
modify the pointer.

{

while (cur)
{
node* next = cur->next;
cur = next;
}
}

Besides the head pointer, you will need two local pointers.

 Is This Answer Correct ? 4 Yes 1 No

How many pointers are required to reverse a link list?..

2 pointers are required....

 Is This Answer Correct ? 7 Yes 6 No

How many pointers are required to reverse a link list?..

using 2 pointer:
{
{
node* aNext = NULL;
while (aCurr)
{
aCurr->next = aNext;
aNext = aCurr;
}
}

}

 Is This Answer Correct ? 1 Yes 2 No

How many pointers are required to reverse a link list?..

# 3 using 2 pointer:
{
{
node* aNext = NULL;
while (aCurr)
{
aCurr->next = aNext;
aNext = aCurr;
}
}

}

 Is This Answer Correct ? 1 Yes 2 No

More C++ General Interview Questions

How to change constant values?

What is c++ runtime?

difference between the c++ and c languages

What are the differences between a struct in C and in C++?

What are destructors?

What are the different types of polymorphism in c++?

Define namespace in c++?

What jobs can you get with a c++ certification?

What is flush programming?

Why iomanip is used in c++?

What do you mean by “this” pointer?

What are the advantages of C++ programming compared to C programming?

Categories
• STL (138)
• OOPS (873)
• C++ General (2384)