- Katılım
- 19 Ocak 2023
- Mesajlar
- 9
- Excel Vers. ve Dili
- I am using Microsoft Excel 2019 in English.
Hello,
I'm having trouble reversing a linked list in C++. I'm trying to use the algorithm outlined in this article but I'm having trouble getting the code to work.
I have the following code, which I believe should work, but is not:
I'm hoping someone can help me figure out what I'm doing wrong and get this code to work.
Thanks in advance!
I'm having trouble reversing a linked list in C++. I'm trying to use the algorithm outlined in this article but I'm having trouble getting the code to work.
I have the following code, which I believe should work, but is not:
Kod:
struct Node
{
int data;
struct Node* next;
};
struct Node* reverse(struct Node* head)
{
Node* current = head;
Node* prev = NULL;
Node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
head = prev;
return head;
}
Thanks in advance!