// Main.cpp #include "stdio.h" #include "iostream.h" #include "math.h" #include "string.h" #include "stdlib.h" #include "assert.h" #include "SetDef.h" #include "rankedSetDef.h" #include "subsetHolder.h" #include "LIMITS.H" int RAandMID::Ecount=0; int Cursor::Ecount=0; int RankedSet::Ecount=0; int setMemberHolder::Ecount=0; int subsetHolder::Ecount=0; //This exercise of the ranked set routines files a million //random numbers into a ranked set, loops through them, then //removes them from the set. This should go quickly on recent PC. //If you have a slow PC, you might want to reduce NUMBER on //first line of main. void main(){ int NUMBER = 1000000; RankedSet rs; RAType R; Cursor C; Cursor * cuPtr = &C;; RAandMID RM; int i; printf("\nGO!!\n"); // TEST printf("\nFiling... \n\nNumber filed so far:\n"); for (i=0; ifindNext()) //************BACKWARD LOOP******************* printf("\nLooping (backwards through entire set) \n"); for (RM = rs.findLast(cuPtr); RM.RM_memberID != NULLmID; RM = cuPtr->findPrior()) //***********BODY OF LOOP********************* { if (((i++)%100000)==0) { printf("Removing the %dst member.\n",i); rs.removeThisFromSet(RM); //REMOVES THE nX100,000th member } } printf("\n\nNumber now in set = %d \n\n", rs.NrInSet()); printf("\nRemoving remaining members\n"); printf("\nNumber still in set:\n"); while(rs.NrInSet()>0) { //Use of the following two statements to remove first or last from set RM=rs.removeFirstFromSet(); // RM=rs.removeLastFromSet(); i++; if (i%100000 == 0) { printf("%d\n",rs.NrInSet()); } } printf("\n\nNumber in set = %d \n\n", rs.NrInSet()); if (cuPtr->CuState()!=NotInSet) rs.removeThisCursorFromSet(cuPtr); return; }