class AList {
private:
element items[MLS];
int size;
int Read_int();
void Swap(int pos1, int pos2);
element Read_element();
void exit_method();
public:
void Menu();
void Read();
//void Ran_Gen();
void BubbleSort();
void SelectionSort();
void InsertionSort();
1 2 3 4 5 6 7 8 9
void Print();
void LinearSearch(element target,bool&found,int&position);
void BinarySearch(element target,bool&found,int&position);
};
int main() {
srand(int(time(0)));
cout<< "\n\nSort and Search Demo Program, version 1.0\n"
<< "(c) 2012,\n\n";
1 2 3 4 5 6 7 8 9 10 11 12 13
AList B;
B.Menu();
// B.LinearSearch();
//B.BinarySearch();
system("PAUSE");
}
void AList::Menu() {
element menuchoice;
element target_linear;
bool found_linear;
int position_linear;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
element target_binary;
bool found_binary;
int position_binary;
constint keyboard=1,
random=2,
bubble=3,
insertion=4,
selection=5,
linear=6,
binary=7,
exit=8;
do {
cout<< "Current List: ";
if (menuchoice>0)
Print();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
else
cout<< "(empty)\t";
if ((menuchoice>2)&&(menuchoice<6))
cout<<"(list is known to be ordered)\n\n";
else
cout<<"(list is not know to be ordered)\n\n";
cout<< "Actions:\n";
cout<< " 1. Reset the current list from the keyboard\n";
cout<< " 2. Reset the current list using randomly generated "
<< "elements\n";
cout<< " 3. Perform Bubble Sort on the current list\n";
cout<< " 4. Perform Insertion Sort on the current list\n";
cout<< " 5. Perform Selection Sort on the current list\n";
cout<< " 6. Perform Linear Search on the current list\n";
cout<< " 7. Perform Binary Search on the current list\n";
cout<< " 8. Quit the program\n\n";
/* case 6:{
LinearSearch(target_linear,found_linear,position_linear);
}
break;
case 7: {
BinarySearch(target_binary,found_binary,position_binary);
cout<< "The target was "<<found_binary<< " on the"
<< " current list in position "<<position_binary;
cout<< endl<<endl;
}
break;*/
/* case 8:
exit_method();
break;
default: cout<< "Please enter a valid menu choice: ";
menuchoice=Read_int();
;*/
}
}
while (menuchoice !=8);
}
void AList::Print() {
for (int i=0; i<size; i++)
cout<< items[i]<<" ";
}