-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientList.cpp
More file actions
79 lines (70 loc) · 1.56 KB
/
Copy pathClientList.cpp
File metadata and controls
79 lines (70 loc) · 1.56 KB
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
#include "ClientList.hpp"
#include "Client.hpp"
#include "NodeClient.hpp"
#include <iostream>
using namespace std;
ClientList::ClientList(){
this->first= NULL;
}
Client* ClientList::get(int index){
NodeClient *target = this->first;
int i;
if(target == NULL){
return NULL;
}
for(i = 0; i < index; i++){
target = target->getNext();
if(target==NULL){
break;
}
}
if(target != NULL){
return target->getData();
}else{
return NULL;
}
}
void ClientList::add(Client *data){
NodeClient *target;
NodeClient *newData = new NodeClient(data);
if(first==NULL){
first = newData;
}else{
target = first;
while(target->getNext() != NULL){
target = target->getNext();
}
target->setNext(newData);
}
}
bool ClientList::remove(int index){
NodeClient *target = first;
NodeClient *aux;
int i;
if(target==NULL){
return false;
}
if(index == 0){
first = first->getNext();
target->setNext(NULL);
delete target;
}else{
for(i=0; i<index-1; i++){
target = target->getNext();
if(target==NULL){
break;
}
}
if(target==NULL){
return false;
}else if(target->getNext()==NULL){
return false;
}else{
aux = target->getNext();
target->setNext(target->getNext()->getNext());
aux->setNext(NULL);
delete aux;
}
}
return true;
}