Page 1 of 1

PostPosted: Wed Jan 16, 2002 4:35 am
by Gazza
I have created this topic to build a wealth of programming routines to sort and remove and change data,

Ok these are the sort I things I would like to achive,

*Remove an array from an array list, then re-shuffle the array so that it closes up the gap.

*Insert data into an array in a particular place

* Create an Array and mix up the data

// More to Come // I am working out these problems but would appreciate any help, Thanks everyone.....

Edited by - Gazza on 01/15/2002 22:37:50

PostPosted: Wed Jan 16, 2002 11:09 am
by guy
If you're interested in code that manages "arrays" that can have elements removed and reordered then take at look at my linked list/tree library. You can download the source from the pcform page (link in sig). Although this was written for the CE version of PocketC it should work with both versions (may require some small tweaking for Palm).

It allows you to create collections of items. Items can have several fields and can be reordered or deleted. Items can own other collections of items. Items have constructors and destructors. There are functions to walk the lists and call a function of your choice for each item (like enumerators).

The data structures that it manages are very heavily used in pcform and I've not had any reports of bugs or memory leakage in the code.

It would be easy to add a quicksort function to the library so that a list could be sorted automatically, calling a user defined comparison function for each item.

PocketC CE API interface:

Edited by - guy on 01/16/2002 05:12:31

PostPosted: Thu Jan 17, 2002 9:08 am
by Gazza
It would not install onto the pc, I really want to stay away from the api, I would like to write native code, but I am not quite that far yet & can you write Native Libarys using pocket c, I could possible do most of these tasks, its just the @[] does not work, I have tried this and just get an error

str @[1] = 'W';

PostPosted: Fri Jan 18, 2002 5:05 am
by Gazza
Ok Here The First to Randomize a String

// Random String

string person[3];
string new[6];

nxt(int x, string hold) {
string tmp; int t,y; t=x;
while(x) {
x--; }

while(t) {
hold=hold+new[t]; }
puts(hold); }

main() {
int x;
string hold;
hold = person[0];
x = strlen(hold);
nxt(x,hold); }

This uses Joe Stadolnik Algo to Randomize the Array, I am working on this program with pointers to reduce the code.

PostPosted: Fri Jan 18, 2002 7:45 am
by Gazza
ok here is the same program using pointers, not sure why ret = ctostr(ptr); does not return all data from the pointer, hence the loop.

// Rand String

string per[3];
pointer ptr;

main() {
string str,tmp,ret;
int len,y,i;
str = per[0];
len = strlen(str)+1;
ptr = malloc(len);
settype(ptr, len, 'c');
strtoc(str, ptr);

while(len) {
ptr[i]=tmp; }

// ret = ctostr(ptr);
for(y=0; y<strlen(str)+1; y++)
{puts(ptr[y]); }
free(ptr); }