CS 222 Winter 1999, Instructor: Jeffrey Horn
General
Student Concerns: Colloquia
and Seminars Local
Events NMU
CS Employmen
What's REALLY New:
void SortedArray::InitializeFromFile()
// NOTE: This method has been "fixed" to work with
{
// the array "everyone" being an array of POINTERS to
// individuals. Note the changed lines below, see comments.
char tempchar;
int i,j;
ifstream infile("input");
// Open file for reading.
loIndex=0;
hiIndex=-1;
while(infile)
// Main loop here goes through file line by line,
{
// until end of file.
hiIndex++;
everyone[hiIndex] = new Individual(); // NEW: NEED TO
CREATE NEW INDIV. FOR EACH ARRAY ELEMENT.
for (i = 0; i < CHROMLENGTH; i++) // Inner loop here goes down
a
{
// chromosome bit by bit, reading in
infile.get(tempchar);
// a single character from file as
if(tempchar == '0')
// the next bit.
//
// NEW: NOTE HOW NEXT TWO LINE NOW USE THE "->" OPERATOR,
// SINCE "EVERYONE[i]" IS NOW A POINTER, NOT AN INDIVIDUAL.
everyone[hiIndex]->chromosome[i] = FALSE; // '0'
is FALSE.
else everyone[hiIndex]->chromosome[i] = TRUE; // '1' is TRUE.
};
infile.get(tempchar); //
Get newline character, to skip it.
};
hiIndex--;
// Decrement hiIndex just before returning,
// because it gets incremented one too many times
// loop.
};
We can discuss this on Friday!
If you purchase "Intro to Data Structures
and Algorithm Analysis with C++" by Pothering and Naps, I suggest you return
it for a full refund by Friday, January 15, which I heard is the deadline
at the campus bookstore.
CONTENTS
WEEK OF
Topics
Handouts
Syllabus
WEEK OF
Handouts
Binary Search