A Simple List Class
- This is only a partial implementation of a list.
- We need some additional techniques in c++ to complete this.
- I want to build an ordered list of integers.
- I will support the following methods
-
- A constructor and destructor
- void Insert(int)
- void Delete
- bool IsPresent(int)
- int Size();
- I also want a way to traverse the list so I will add
- The list has an internal pointer to an element in the list.
- Home() will set this to the head of the list.
- bool IsLast() will return true if it is pointing to nullptr
- Next() will move it to the next item in the list, it will not advance past nullptr
- int Current() will return the int at the current position, or -1 if there is nothing.
-
- Review this, what do all of the fields mean?
- This is akin to an iterator we will study later.
- The data for this list is
- head, a pointer to the first node or nullptr
- current, a pointer to a node in the list or nullptr
- size, an integer representing the size of the list.
- Why store size? Why not compute it each time?
- The ListT.h file
-
#pragma once
- This is equivalent to the guards and is perfectly acceptable.
- Note the forward definition of the NodeT
- We can have a partial definition as we only declare a pointer to this structure.
- The rest will be declared in ListT.cpp.