Question: Complete the code, where it says TO DO code: #ifndef __SLLIST_H__ #define __SLLIST_H__ #include Node.h #include // size should not be negative typedef unsigned long
Complete the code, where it says "TO DO"
code:
| #ifndef __SLLIST_H__ | |
| #define __SLLIST_H__ | |
| #include "Node.h" | |
| #include | |
| // size should not be negative | |
| typedef unsigned long size_t; | |
| namespace ds { | |
| template | |
| /** Singly linked list. */ | |
| template | |
| class SLList { | |
| friend class TestDriver | |
| private: | |
| /** Pointer pointing to the sentinel node. */ | |
| Node | |
| /** Stores the current size of the list. */ | |
| size_t count; | |
| public: | |
| /** Construct a new SLList object. */ | |
| SLList() { | |
| sentinel = new Node | |
| count = 0; | |
| } | |
| /** Add x at the beginning of the list. */ | |
| void addFirst(ItemType x) { | |
| count += 1; | |
| sentinel->next = new Node | |
| } | |
| /** Return the first element. */ | |
| ItemType &getFirst() const { | |
| assert(sentinel->next != nullptr); | |
| return sentinel->next->item; | |
| } | |
| /** Return the number of elements in list. */ | |
| size_t size() const { return count; } | |
| /** Append the list with x. */ | |
| void addLast(ItemType x) { | |
| count += 1; | |
| Node | |
| while (p->next != nullptr) { | |
| p = p->next; | |
| } | |
| p->next = new Node | |
| } | |
| SLList(const SLList | |
| ~SLList(); | |
| ItemType &get(int i) const; | |
| ItemType removeFirst(); | |
| ItemType removeLast(); | |
| }; | |
| /** Copy constructor. */ | |
| template | |
| SLList | |
| // TODO: create a list that is identical to `other` | |
| } | |
| /** Destroy the SLList object. */ | |
| template | |
| SLList | |
| // TODO: | |
| } | |
| /** Return the i-th item in list. */ | |
| template | |
| ItemType &SLList | |
| // TODO: | |
| } | |
| /** Delete and return the first item of the list. */ | |
| template | |
| ItemType SLList | |
| // TODO: | |
| } | |
| /** Delete and return the last item of the list. */ | |
| template | |
| ItemType SLList | |
| // TODO: | |
| } | |
| } // namespace ds | |
| #endif // __SLLIST_H__ |
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
