How many pointers are required to reverse a link list?
Answer Posted / prits
Using 3 pointers:
curr, next, result pointers, curr points to current node,
next obviously points to the next node, result points to
the new reversed linked list
void reverse_single_linked_list(struct node** headRef)
{
struct node* result = NULL;
struct node* current = *headRef;
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;
}
*headRef = result;
}
| Is This Answer Correct ? | 14 Yes | 1 No |
Post New Answer View All Answers
In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that
Evaluate as true or false: !(1 &&0 || !1) a) True b) False c) Invalid statement
Define the operators that can be used with a pointer.
In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h
What is the use of function pointer?
How do I run c++?
What is virtual destructor ans explain its use?
Do class declarations end with a semicolon? Do class method definitions?
What programming language should I learn first?
Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. Your program should work for squares of all side sizes between 1 and 20. --- │ │ │ │ │ │ ---
what is multi-threading in C++?
Explain the concept of dynamic allocation of memory?
Which is not a valid keyword a) public b) protected c) guarded
Explain selection sorting. Also write an example.
which of the following is not an secondary constant a) array b) real c) union