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

What is Name Decoration?

write a program that a 5 digit number and calculates 2 power that number and prints it.

Give a very good method to count the number of ones in a "n" (e.g. 32) bit number.

If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2.

what is oops

template<class T, class X> class Obj { T my_t; X my_x; public: Obj(T t, X x) : my_t(t), my_x(x) { } }; Referring to the sample code above, which one of the following is a valid conversion operator for the type T? a) T operator T () { return my_t; } b) T operator(T) const { return my_t; } c) operator(T) { return my_t; } d) T operator T (const Obj &obj) { return obj.my_t; } e) operator T () const { return my_t; }

const char * char * const What is the differnce between the above two?

Write a program that will count the number of digits in an input integer up to value MAX_VALUE (2147483647). Thus, for an input of 5837 the output should be 4 digits Make sure that your program works for the numbers 0, 1, and 10. For the number 0, the output should be 1 digit

WHO DEVELOPED C++?

What is "mutable" keyword?

What are raw sockets, where they are efficient?

Write a program to get the value of sin (x) using a library function , when x is given in degrees.

Categories