shushus

Спринт 7. Как устроен односвязный список.

Jan 12th, 2023
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <cassert>
  2. #include <cstddef>
  3. #include <string>
  4. #include <utility>
  5.  
  6. template <typename Type>
  7. class SingleLinkedList {
  8.     struct Node {
  9.         Node() = default;
  10.         Node(const Type& val, Node* next) : value(val), next_node(next) {}
  11.         Type value;
  12.         Node* next_node = nullptr;
  13.     };
  14.  
  15. public:
  16.     SingleLinkedList() {}
  17.  
  18.     [[nodiscard]] size_t GetSize() const noexcept {
  19.         return size_;
  20.     }
  21.  
  22.     [[nodiscard]] bool IsEmpty() const noexcept {
  23.         if (!size_) {
  24.         return true;
  25.         }
  26.         return false;
  27.     }
  28.  
  29. private:
  30.     Node head_;
  31.     size_t size_ = 0;
  32. };
  33.  
  34. void Test0() {
  35.     using namespace std;
  36.     {
  37.         const SingleLinkedList<int> empty_int_list;
  38.         assert(empty_int_list.GetSize() == 0u);
  39.         assert(empty_int_list.IsEmpty());
  40.     }
  41.  
  42.     {
  43.         const SingleLinkedList<string> empty_string_list;
  44.         assert(empty_string_list.GetSize() == 0u);
  45.         assert(empty_string_list.IsEmpty());
  46.     }
  47. }
  48.  
  49. int main() {
  50.     Test0();
  51. }
Advertisement
Add Comment
Please, Sign In to add comment