-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bda7ae3
commit d55e9aa
Showing
6 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <gtest/gtest.h> | ||
|
||
struct ListNode { | ||
int32_t value; | ||
ListNode *next; | ||
}; | ||
|
||
class Solution { | ||
public: | ||
static auto reverse_list(ListNode *head) -> ListNode* { | ||
if (head == nullptr) return head; | ||
|
||
ListNode *current = head; | ||
ListNode *prev = nullptr; | ||
|
||
while (current != nullptr) { | ||
ListNode *next = current->next; | ||
current->next = prev; | ||
prev = current; | ||
current = next; | ||
} | ||
|
||
return prev; | ||
} | ||
|
||
static auto insert(ListNode **head_ref, | ||
const int32_t new_value) -> void { | ||
auto *node = new ListNode(); | ||
node->value = new_value; | ||
node->next = (*head_ref); | ||
(*head_ref) = node; | ||
} | ||
|
||
static auto print(ListNode *head) -> void { | ||
while (head != nullptr) { | ||
std::cout << head->value << ' '; | ||
head = head->next; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "../include/solution.hpp" | ||
|
||
auto main() -> int { | ||
ListNode *node = nullptr; | ||
Solution::insert(&node, 5); | ||
Solution::insert(&node, 4); | ||
Solution::insert(&node, 3); | ||
Solution::insert(&node, 2); | ||
Solution::insert(&node, 1); | ||
|
||
Solution::print(node); | ||
std::cout << '\n'; | ||
node = Solution::reverse_list(node); | ||
Solution::print(node); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <gtest/gtest.h> | ||
|
||
struct ListNode { | ||
int32_t value; | ||
ListNode *next; | ||
}; | ||
|
||
class Solution { | ||
public: | ||
static auto pair_sum(ListNode *head) -> int32_t { | ||
|
||
} | ||
|
||
static auto insert(ListNode **head_ref) | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters