Building a List ADT
A list is a sequence of items with similar data types, where the order of the item's position matters.There are several common operations that are available in a List ADT, and they are:
Get(i)
, which will return the value of selected index,i
. If thei
index is out of bounds, it will simply return-1
.Insert(i, v)
, which will insert thev
value at the position of indexi
.Search(v)
, which will return the index of the first occurrence ofv
(if thev
value doesn't exist, the return value is-1
).Remove(i)
, which will remove the item in thei
index.
Note
For simplicity, we are going to build a List ADT that accepts int
data only, from zero (0) and higher.
Now, by using the array data type we discussed earlier, let's build a new ADT named List
which contains the preceding operations. We need two variables to hold the list of items (m_items
) and the number of items in the list (m_count
). We will make them private
so that it cannot be accessed from the outside class. All four operations...