Ik had een programma waar ik gebruik maakte van een enkelgelinktelijst. Nu ging ik dit uitbreiden om te bladeren door de objecten heen. Helaas ging dat niet goed. Ik heb de functie Add niet goed. Dat is dan nog maar van de enkelgelinkte lijst, ik kan er maar eentje terug bladeren en niet meer. Nu wil ik dus ook weer dieper de lijst in kunnen. Dus moest ik de Add functie uitbreiden zodat de Previous pointer etc ook goed gezet word. Dit lukt me dus voor geen meter.
---------------CQueue.h--------------------------
-------Cqueue.cpp-------------------------------
--------functie.cpp--------------------------------------
---------------------------------------------------------
Please help me
---------------CQueue.h--------------------------
code:
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
| class CData{
public:
CData( const char *contactname,
const char *number1,
const char *number2,
const char *email); // Constructor
CData();
~CData(){};//Destructor
char * getContactname(){return contactname;}
//pre: -
//post: Returns the data in the variable 'documentnaam'
char * getNumber1(){return number1;}
//pre: -
//post: Returns the data in the variable 'eigenaar'
char * getNumber2(){return number2;}
//pre: -
//post: Returns the data in the variable 'status'
char * getEmail(){return email;}
//pre: -
//post: Returns the data in the variable 'datum'
private:
char *contactname;
char *number1;
char *number2;
char *email;
};
class Node{
public:
Node(){};
~Node(){};
void SetInhoud(CData *cdD);
void SetNext(Node *next2);
void SetPrevious(Node *next3);
CData * GetInhoud();
Node * GetNext();
Node * GetPrevious();
//private:
CData *cdInhoud;
Node *next;
Node *previous;
};
class CQueue {
public:
CQueue():iTeller(0){}//Constructor
~CQueue(){}; // Destructor
bool isEmpty( );
CData *first( );
CData *next( );
CData *previous( );
void add(CData *cdD );
void remove( );
void clear( );
int getSize( ){return iTeller;}
private:
Node *frontnode;
Node *backnode;
Node *current;
int iTeller;
};
CQueue *CQueueInstant(){
CQueue *pcqQ = new CQueue;
return pcqQ;
}
extern CQueue *qQ;
extern CData *data; |
-------Cqueue.cpp-------------------------------
code:
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
| #include <string.h>
#include <iostream.h>
#include <iomanip.h>
#include <time.h>
#include <windows.h>
#include <stdlib.h>
#include "database.h"
CQueue *qQ = CQueueInstant();
CData *data = 0;
//Add a new node to the linked list.
void CQueue::add(CData *cdD )
{
if (iTeller == 0)
{
Node *temp = new Node;
temp->next=frontnode;
temp->cdInhoud=cdD;
temp->previous=backnode;
frontnode = temp;
iTeller++;
}
else
{
Node *temp = new Node;
temp->next=frontnode;
temp->cdInhoud=cdD;
temp->previous=backnode;
current = temp;
iTeller++;
}
}
//Remove a node from the list.
void CQueue::remove( )
{
Node *temp= frontnode ;
Node *temp1;
int iT=iTeller;
switch( iTeller )
{
case 0:
cout<<"The Que is empty !"<<endl;
break;
case 1:
frontnode=NULL;
delete temp;
break;
case 2:
temp=temp->GetNext();
frontnode->SetNext(NULL);
delete temp;
break;
default :
while (iT >= 3){
temp=temp->GetNext();
iT--;
}
temp1=temp->GetNext();
temp->SetNext(NULL);
delete temp1;
break;
}
iTeller--;
}
CData * CQueue::previous()
{
Node *qTemp=frontnode;
CData *dTemp;
if (iTeller==0 || iTeller == 1)
{
}
else
{
qTemp=qTemp->GetNext();
}
dTemp=qTemp->GetInhoud();
return dTemp;
}
CData * CQueue::next()
{
Node *qTemp=frontnode;
CData *dTemp;
if (iTeller==0 || iTeller == 1)
{
}
else
{
qTemp=qTemp->GetPrevious();
}
dTemp=qTemp->GetInhoud();
return dTemp;
}
//Return a pointer to the Data of the first node from the Que.
CData * CQueue::first()
{
Node *qTemp=frontnode;
CData *dTemp;
int iT=iTeller;
if (iTeller==0)
{
cout<<"There is no data"<<endl;
}
else
{
while (iT >= 2){
qTemp=qTemp->GetNext();
iT--;
}
}
dTemp=qTemp->GetInhoud();
return dTemp;
}
//Clears the entire list.
void CQueue::clear( )
{
Node *qTemp=frontnode;
while (iTeller >= 1){
frontnode=qTemp->GetNext();
delete qTemp;
qTemp=frontnode;
iTeller--;
}
frontnode=NULL;
iTeller=0;
}
//Cheks if the list is empty.
bool CQueue::isEmpty( )
{
Node *qTemp=frontnode;
if (iTeller==0)
{
return true;
}
else
{
return false;
}
}
//Set function of the Data part for a Node.
void Node::SetInhoud(CData *cdD)
{
cdInhoud=cdD;
}
//Set function of the NextNode part for a Node.
void Node::SetNext(Node *next2)
{
next=next2;
}
void Node::SetPrevious(Node *previous2)
{
previous=previous2;
}
//Returns the NextNodepointer of a Node.
Node * Node::GetNext()
{
return next;
}
Node * Node::GetPrevious()
{
return previous;
}
//Returns the Inhoudpointer of a Node.
CData * Node::GetInhoud()
{
return cdInhoud;
}
//Returns a pointer to a new Que list.
//Constructor CData
CData::CData(const char *Contactname,
const char *Number1,
const char *Number2,
const char *Email)
{
contactname = new char[strlen(Contactname)+1];
number1 = new char[strlen(Number1)+1];
number2 = new char[strlen(Number2)+1];
email = new char[strlen(Email)+1];
strcpy(contactname,Contactname);
strcpy(number1,Number1);
strcpy(number2,Number2);
strcpy(email,Email);
} |
--------functie.cpp--------------------------------------
code:
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
| CData *InsertJob(char *CNaam, char *N1, char *N2, char *EM)
{
CData *temp= new CData(CNaam, N1, N2, EM);
return temp;
}
//---------------------------------------------------------------------------
void Clearfile(){
ofstream examplefile ("example.txt",ios::trunc);
}
//---------------------------------------------------------------------------
void Writedata(CData *cdDa, CQueue *qQueue)
{
ofstream examplefile ("example.txt",ios::ate);
if (examplefile.is_open())
{
examplefile << cdDa->getContactname() <<"\n";
examplefile << cdDa->getNumber1() << "\n";
examplefile << cdDa->getNumber2() << "\n" ;
examplefile << cdDa->getEmail() << "\n";
examplefile.close();
}
}
//---------------------------------------------------------------------------
bool IsEmpty(char *String)
{
char string[50]="";
if (strcmp(String,string) == 0)
{
return false;
}
else
{
return true;
}
} |
---------------------------------------------------------
Please help me