-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.hpp
73 lines (52 loc) · 2 KB
/
List.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// List.hpp
// List
// A doubly-liked list implementation for class project CSci 235 Software Design and Analysis II
//
// Created by Tiziana Ligorio on 10/21/18.
// Modified 6/5/19
// Copyright © 2018 Tiziana Ligorio. All rights reserved.
//
#ifndef LIST_H_
#define LIST_H_
#include <iostream>
#include "Node.hpp"
#include "PrecondViolatedExcep.hpp"
template<class T>
class List
{
public:
List(); // constructor
List(const List<T>& a_list); // copy constructor
~List(); // destructor
/**@return true if list is empty - item_count_ == 0 */
bool isEmpty() const;
/**@return the number of items in the list - item_count_ */
size_t getLength() const;
/**
@param position indicating point of insertion
@param new_element to be inserted in list
@post new_element is added at position in list (the node previously at that position is now at position+1)
@return true always - it always inserts, if position > item_count_ it inserts at end of list */
bool insert(size_t position, const T& new_element);
/**
@param position indicating point of deletion
@post node at position is deleted, if any. List order is retains
@return true if ther eis a node at position to be deleted, false otherwise */
bool remove(size_t position);
/**
@pre assumes there is an item at position - NO ERROR HANDLING
@param position of item to be retrieved
@return the item at position in list if there is one, otherwise it throws exception: PrecondViolatedExcep */
T getItem(size_t position) const;
/**@post the list is empty and item_count_ == 0*/
void clear();
protected:
Node<T>* first_; // Pointer to first node
Node<T>* last_; // Pointer to last node
size_t item_count_; // number of items in the list
//if position > item_count_ returns nullptr
Node<T>* getPointerTo(size_t position) const;
}; // end List
#include "List.cpp"
#endif // LIST_H_