-
Notifications
You must be signed in to change notification settings - Fork 0
/
List_interface.h
88 lines (77 loc) · 1.84 KB
/
List_interface.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef LIST_INTERFACE_H
#define LIST_INTERFACE_H
#include "my_list.h"
#include <string>
using std::string;
enum list_type{
t_int, t_double, t_char };
class List_interface
{
public:
List_interface(list_type =t_int);
~List_interface();
template <typename T>
void push_back(T val);
template <typename T>
void push_front(T val);
void pop_back();
void pop_front();
void sort();
void reverse();
string show();
void deleteAt(int pos);
template <typename T>
void insertAt(int, T);
private:
List_base * m_lst;
list_type m_type;
};
template <typename T>
void List_interface::push_back(T val)
{
switch (m_type)
{
case t_int:
static_cast <List <int> * > (m_lst)->push_back(val);
break;
case t_double:
static_cast <List <double> * > (m_lst)->push_back(val);
break;
case t_char:
static_cast <List <char> * > (m_lst)->push_back(val);
break;
}
}
template <typename T>
void List_interface::push_front(T val)
{
switch (m_type)
{
case t_int:
static_cast <List <int> * > (m_lst)->push_front(val);
break;
case t_double:
static_cast <List <double> * > (m_lst)->push_front(val);
break;
case t_char:
static_cast <List <char> * > (m_lst)->push_front(val);
break;
}
}
template <typename T>
void List_interface::insertAt(int pos, T val)
{
switch (m_type)
{
case t_int:
static_cast <List <int> * > (m_lst)->insertAt(pos, val);
break;
case t_double:
static_cast <List <double> * > (m_lst)->insertAt(pos, val);
break;
case t_char:
static_cast <List <char> * > (m_lst)->insertAt(pos, val);
break;
}
}
#endif