$ ../public/assn1.tools/set_stack_offset ../public/assn1 ... lots of output ... $If you want to redirect input from a file to the program, do it via
$ ../public/assn1.tools/set_stack_offset ../public/assn1 < attack_data You got it! $The assignment is now due at Feb 5, 2000, 2359 PST.
void sort(int array[],
int nelt)
{
int i, j, t;
for (i = 0; i < nelt; i++) for (j = 0; j < nelt; j++)
if (array[j] > array[j+1]) {
t = array[j];
array[j] = array[j+1];
array[j+1] = t;
}
}
A more pointer oriented sort:
void sort(int array[],
int nelt)
{
int i, t, *ip, *ipend;
ipend = array + nelt;
for (i = 0; i < nelt; i++) {
for (ip = array; ip < ipend; )
if (*ip > *ip++) {
t = *ip;
*ip = ip[-1];
ip[-1] = t;
}
}
}
A search algorithm:
struct record {
int key;
struct data *datap; /* ... */
}
struct record *find_rec(struct record *p, int nrec, int key)
{
int mid = nrec/2;
if (record[mid].key == key) return record+mid;
if (record[mid].key < key)
return find_rec(p,mid-1,key);
return find_rec(p+mid+1,nrec-(mid+1),key);
}
bsy+cse127w02@cs.ucsd.edu, last updated
email bsy.