Ok, I've been trying to find and solve the problem with this source code by using the ddd debuger and I just can't. Here is the code.
//lab1.cc, a driver for list.cc
//CSCI 1120
//Will Briggs
#include <iostream.h>
#include "list.h"
main ()
{
Item Letters [MAX_ITEMS]; int num_letters = 0;
insert (Letters, num_letters, 'A');
insert (Letters, num_letters, 'D');
insert (Letters, num_letters, 'R');
insert (Letters, num_letters, 'E');
insert (Letters, num_letters, 'T');
insert (Letters, num_letters, 'M');
insert (Letters, num_letters, 'V');
insert (Letters, num_letters, 'P');
insert (Letters, num_letters, 'Q');
insert (Letters, num_letters, 'X');
print (Letters, num_letters);
}
//list.cc, containing functions for operations on an ordered list
//CSCI 1120
//Will Briggs
#include <iostream.h>
#include "list.h"
void insert (Item List[], int& howmany, Item thing)
{
if (howmany == MAX_ITEMS)
cerr << "Error in insert: can't add " << thing
<< ", list is full!" << endl;
else
{
int where = INITIAL_VALUE;
while (thing > List[where] && where < howmany) where++;
//go till at or past position
//of thing OR at end of list
for (int i = howmany; i > where; i--) //shift all subsequent items
List = List[i-1]; //down list by 1
List[where] = thing; //finally, add thing in place
howmany++;
}
}
int search (Item List[], int howmany, Item thing)
{
int i = 0;
while (thing > List && i < howmany-1) i++; //go till at or past position
//of thing OR at end of list
if (List == thing) return i; else return NOT_FOUND;
}
void print (Item List[], int howmany)
{
for (int i = 0; i < howmany; i++) cout << List << endl;
cout << endl;
}
I know that the two variables that are in red have a wrong value but I can't seem to find the way to change that, if that is the problem.
If someone could give me a hand or a hint with this that would be great.
Thanks a lot.