-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.h
69 lines (53 loc) · 1.2 KB
/
List.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
//========================================================
// K M I Asif
// April 2023
// List.h
// This file contains the List class declaration.
//========================================================
#include <iostream>
#include <string>
using namespace std;
#ifndef LIST_H
#define LIST_H
#define DEFAULT_LIST_CAPACITY 10
template <class T>
class List
{
private:
// struct for Node for linked list
struct Node
{
T item;
Node *next;
};
Node *head; // the pointer for the linked list
public:
List ( void );
List ( const List<T> &mylist );
~List ( void );
List<T> operator= ( const List<T> &mylist );
string to_string ( void ) const;
void append ( const T &item );
T & operator[] ( int index );
void insert ( const T &item, int index );
void remove ( int index );
List<T> operator+ ( const List<T> &mylist ) const;
int length ( void ) const;
bool isEmpty ( void ) const;
void clear ( void );
friend ostream & operator<< ( ostream &os, List<T> &mylist )
{
Node *ptr = mylist.head;
while ( ptr != NULL )
{
if ( ptr->next != NULL )
os << ptr->item << " ";
else
os << ptr->item;
ptr = ptr->next;
}
return os;
}
};
#include "List.cpp"
#endif