program wanted

hello guys

i am in need of a project of about 1000 lines using functions loops class and structures.......
Are you asking for an *idea* for a small project,
or are you asking for someone to give you the code?
I don't NORMALLY give this away. It is my (Beta testing needed) list.h file. If it serves a purpose to have an arbitrarily long list, take up 261 lines of code, AND knock of the function, class, and structure criteria for your little dilemma, I'll be glad to give it away.

(Get it quickly, I really don't want this to remain here for a really long time.)

Oh, yeah, about the assert(cond, msg):
go to your assert.h file and modify this:
1
2
3
#  define assert(p, msg) ((p) ? (void)0 : (void) __assertfail( \
						  "Assertion failed: %s, file %s, line %d\n" _ENDL, \
                    #p, __FILE__, __LINE__ ) ) 

to this:
1
2
3
#  define assert(p, msg) ((p) ? (void)0 : (void) __assertfail( \
						  "Assertion failed: %s, file %s, line %d\n"##msg _ENDL, \
                    #p, __FILE__, __LINE__ ) ) 


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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#ifndef LIST_H
#define LIST_H

#include <assert.h>

//Remove/Search flags
#define FIRST 1
#define LAST 2
#define ALL 3     //Used with HOWMANY
#define POS(x) (0-(x))

//Used with Search
#define ASINDEX 1
#define ASREST 2
#define HOWMANY 3

template <class TC1>
struct SEARCHRESULT{
int success;
union{
TC1 *rest;
int index;
int howmany;
};
int which;
};


template <class T>
class List{
public:
List();
List(T *);
List(int);
~List();
void Set(int, T);
T Get(int);
void Append(T);
short Remove(T, int);
void Truncate(int);
int Size();
T *Array();
SEARCHRESULT<T> Search(T, int, int);
void Reset(int, T);
T &operator()(int);
T &operator[](int);
void operator+=(T);
void operator+=(List); //NDEF
List operator+(T);

private:
T *list;
int size;
};

template <class T>
List<T>::List()
{
size=0;
list=new T[2];
}

template <class T>
List<T>::List(T *li)
{
int j;
size=sizeof(li)/sizeof(T);
list=new T[size];
for(j=0; j<size; j++)
list[j]=li[j];
}

template <class T>
List<T>::List(int init)
{
int j;
T def;
size=init;
list=new T[size];
for(j=0; j<size; j++)
list[j]=def;
}

template <class T>
void List<T>::Set(int indice, T val)
{
assert(indice>=0&&indice<size, "Indice out of range in List::Set");
list[indice]=val;
}

template <class T>
T List<T>::Get(int indice)
{
assert(indice>=0&&indice<size, "Indice out of range in List::Get");
return list[indice];
}

template <class T>
void List<T>::Append(T val)
{
T *li;
int j;
li=new T[size++];
for(j=0; j<size-1; j++)
li[j]=list[j];
delete [] list;
list=new T[size];
for(j=0; j<size-1; j++)
list[j]=li[j];
list[size-1]=val;
}

template <class T>
short List<T>::Remove(T val, int which)
{
int j, i, f=0;
switch(which){
case FIRST:
for(j=0; j<size; j++)
if(list[j]==val){
for(i=j; i<size-1; i++)
list[i]=list[i+1];
Truncate(1);
return 1;}
return 0;
break;

case LAST:
for(j=size-1; j>=0; j--)
if(list[j]==val){
for(i=j; i<size-1; i++)
list[i]=list[i+1];
Truncate(1);
return 1;}
return 0;
break;

case ALL:
for(j=0; j<size; j++)
if(list[j]==val){
for(i=j; i<size-1; i++)
list[i]=list[i+1];
Truncate(1);
f=1;}
return f;
break;

default: //POS
for(j=0; j<size; j++)
if(list[j]==val)
if(++f==(which*-1)){
for(i=j; i<size-1; i++)
list[i]=list[i+1];
Truncate(1);
return 1;}
return 0;
break;}
}

template <class T>
void List<T>::Truncate(int sz)
{
T *buf;
int j;
buf=new T[size-sz];
for(j=0; j<size-sz; j++)
buf[j]=list[j];
delete [] list;
list=new T[size-=sz];
for(j=0; j<size; j++)
list[j]=buf[j];
delete [] buf;
}

template <class T>
T *List<T>::Array() {return list;}

template <class T>
SEARCHRESULT<T> List<T>::Search(T val, int which, int ret)
{
int j;
SEARCHRESULT<T> sr;
sr.which=ret;
sr.success=0;
sr.howmany=0;
assert((which==ALL)?(ret==HOWMANY):(ret==ASINDEX||ret==ASREST), "Parameter mismatch in List::Search");
switch(which){
case FIRST:
for(j=0; j<size; j++)
if(list[j]==val){
if(ret==ASINDEX)
sr.index=j;
else
sr.rest=&list[j];
sr.success=1;}
return sr;
break;

case LAST:
for(j=size-1; j>=0; j++)
if(list[j]==val){
if(ret==ASINDEX)
sr.index=j;
else
sr.rest=&list[j];
sr.success=1;}
return sr;
break;

case ALL:
for(j=0; j<size; j++)
if(list[j]==val){
sr.howmany++;
sr.success=1;}
return sr;
break;

default:
for(j=0; j<size; j++)
if(list[j]==val)
if(++sr.howmany==(which*-1)){
if(ret==ASINDEX)
sr.index=j;
else
sr.rest=&list[j];
sr.success=1;}
return sr;
break;}
}

template <class T>
void List<T>::Reset(int sz, T fill)
{
int j;
delete [] list;
list=new T[sz];
size=sz;
for(j=0; j<size; j++)
list[j]=fill;
}

template <class T>
void List<T>::operator+=(T val) {Append(val);}

template <class T>
T &List<T>::operator()(int indice) {return operator[](indice-1);}

template <class T>
int List<T>::Size() {return size;}

template <class T>
T &List<T>::operator[](int indice)
{
assert(indice<size, "Indice out of range in List::operator[]");
return list[indice];
}

template <class T>
List<T>::~List() {delete [] list;}

#endif 


E-mail me at grahamnorthup@yahoo.com and tell me how it works! Use subject LIST
Last edited on
Topic archived. No new replies allowed.