Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ class Node {
class SinglyLinkedList {
private:
Node* head;
Node* recucrsiveFunction(Node* p) {
Node* q = p->next;
if (q->next) {
Node* newNode = q->next;
q->next = p;
return recucrsiveFunction(q);
}else {
return nullptr;
}
}

public:
SinglyLinkedList() : head(nullptr) {}
Expand All @@ -36,8 +46,17 @@ class SinglyLinkedList {
}

void reverseLinkedList() {
// TODO: Students will implement this function
std::cout << "Implement reverseLinkedList()" << std::endl;
Node* a = head;
Node* b = a->next;
a->next = nullptr;
while (b->next) {
Node* temp = b->next;
b->next = a;
a = b;
b = temp;
}
b->next = a;
head = b;
}
};

Expand Down