1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #ifndef SORTED_LIST_H
- #define SORTED_LIST_H
-
- #include <string>
-
- /*
- Lab 3 - TDDE18 - Sorted list lab - Header file
- Last modification : 2020-09-30
- */
-
- // Note: The other TODO remarks are in the test_list.cc file
-
- //TODO: Complementary work needed, 8-8: The link class and any functions pertaining it
- // should be stashed away and inaccessible to user. --> done (by moving Node struct declaration
- // in Sorted_List private part).
- //TODO: Complementary work needed, 8-8: Should have a function at() which should get
- // a value from place n in list. --> done (by implementing at() function and creating tests).
-
- //COMMENT: Good job with no memory leaks!
-
-
- /// A structure representing a list node
- /*
- struct Node {
- int value;
- Node* next;
- };*/
-
- /// A class representing a sorted list
- /// The list is sorted from smallest to largest value
- class Sorted_List{
- public:
-
- /// Constructors
- // Default constructor
- Sorted_List();
- // Copy constructor
- Sorted_List(Sorted_List const& other);
- // "Nice" constructor (actually, no idea how to name it)
- Sorted_List(std::initializer_list<int> list);
- // Move constructor
- Sorted_List(Sorted_List&& other);
-
- /// Destructor
- ~Sorted_List();
-
- // Copy assignment operator
- Sorted_List& operator=(Sorted_List const& other);
- // Move assignment operator
- Sorted_List& operator=(Sorted_List&& other);
-
- // Insert a value in the list
- void insert(int val);
- // Remove a value of the list, raise error if the value does not exist
- void remove(int val);
- // Check if a list is empty
- bool is_empty() const;
- // Return the size of a list
- int size() const;
- // Return the value at a given position
- int at(int pos) const;
- // Convert a list to string
- std::string to_string() const;
-
- private:
- struct Node {
- int value;
- Node* next;
- };
- Node* first{};
- void insert(Node*& first, int val);
- };
-
- #endif
|