Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// File name: -ftp/pub/class/170/ftp/cpp/Binary Search/ BinSearch.cpp // Purpose implementatin of BinSearch.h #include BinSearch.h using namespace std; // Function: void GenerateArray(IntArrayType IntArray, int Count) // Purpose:

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
// File name: -ftp/pub/class/170/ftp/cpp/Binary Search/ BinSearch.cpp // Purpose implementatin of BinSearch.h #include "BinSearch.h" using namespace std; // Function: void GenerateArray(IntArrayType IntArray, int Count) // Purpose: Generate an array of random integers in ascending order // Parameters: IntArray: Array of integers in acending order 1. Count: The number of integers in the array // Return: None void generateArray(IntArrayType intArray, int count) { int i; srand((unsigned) time(NULL)); // seed the rand() function intArray[0] = rand()%10; // pick a random number as the first value for (j = 1; j "; } cout currentlndex) { temp = intArray[indexOfMax]; intArray[indexOfMax] = intArray[currentindex]: intArray(currentIndex] = temp; } intArray[indexOf Max] = intArray(currentIndex]: intArray(currentindex] = temp: // Function: void GenerateArray(IntArrayType IntArray, int Count); // Purpose: Given "Count", generate "Count" number of random integers // and put them in IntArray // Parameters: IntArray: an integer array to hold MAXINDEX elements II Count: number of elements in the array // Return: None void generateArray(IntArrayType intArray, int count) { int k; srand((unsigned) time(NULL)); // seed the random number generator for (k = 0; k #include || needed by setw #include I needed for random number generator #include // used to seed random numbers using namespace std; const int MAXINDEX = 100; || define a type with the name IntArrayType // when we need to declare an int array with MAXINDEX elements, // we could simple write: IntArrayType IntArray; // IntArray is big enough to hold MAXINDEX integers. typedef int IntArrayType[MAXINDEX]; // Function prototypes: void selSort(IntArrayType intArray, int count); void generateArray(IntArrayType intArray, int count); void printArray(IntArrayType intArray, int count); // File name: --ftp/pub/class/170/ftp/cpp/Selection Sort/ SelMain.cpp Il Purpose: Driver program for selection sort #include "SelSort.h" using namespace std; int main(void) { IntArrayType intArray; generateArray (intArray, MAXINDEX); // generate 100 random integers cout #include // needed for setw #include // needed for random number generator #include // used to seed random numbers using namespace std; const int MAXINDEX = 100; typedef int IntArrayType(MAXINDEX]; // Function prototypes: int binary Search(IntArrayType intArray, int low, int high, int target); void generateArray(IntArrayType intArray, int count); void printArray(IntArrayType intArray, int count); // File name: -ftp/pub/class/170/ftp/cpp/BinarySearch/ BinMain.cpp // Purpose: Driver program for binary search program #include "BinSearch.h" using namespace std; int main(void) { IntArrayType intArray; int number, pos; generateArray (intArray, MAXINDEX); // generate sorted integer array cout > number; pos = binarySearch(intArray, O, MAXINDEX - 1, number); if(pos == -1) cout "; for (k = 0; k "; } cout currentlndex) { temp = intArray[indexOfMax]; intArray[indexOfMax] = intArray[currentindex]: intArray(currentIndex] = temp; } intArray[indexOf Max] = intArray(currentIndex]: intArray(currentindex] = temp: // Function: void GenerateArray(IntArrayType IntArray, int Count); // Purpose: Given "Count", generate "Count" number of random integers // and put them in IntArray // Parameters: IntArray: an integer array to hold MAXINDEX elements II Count: number of elements in the array // Return: None void generateArray(IntArrayType intArray, int count) { int k; srand((unsigned) time(NULL)); // seed the random number generator for (k = 0; k #include || needed by setw #include I needed for random number generator #include // used to seed random numbers using namespace std; const int MAXINDEX = 100; || define a type with the name IntArrayType // when we need to declare an int array with MAXINDEX elements, // we could simple write: IntArrayType IntArray; // IntArray is big enough to hold MAXINDEX integers. typedef int IntArrayType[MAXINDEX]; // Function prototypes: void selSort(IntArrayType intArray, int count); void generateArray(IntArrayType intArray, int count); void printArray(IntArrayType intArray, int count); // File name: --ftp/pub/class/170/ftp/cpp/Selection Sort/ SelMain.cpp Il Purpose: Driver program for selection sort #include "SelSort.h" using namespace std; int main(void) { IntArrayType intArray; generateArray (intArray, MAXINDEX); // generate 100 random integers cout #include // needed for setw #include // needed for random number generator #include // used to seed random numbers using namespace std; const int MAXINDEX = 100; typedef int IntArrayType(MAXINDEX]; // Function prototypes: int binary Search(IntArrayType intArray, int low, int high, int target); void generateArray(IntArrayType intArray, int count); void printArray(IntArrayType intArray, int count); // File name: -ftp/pub/class/170/ftp/cpp/BinarySearch/ BinMain.cpp // Purpose: Driver program for binary search program #include "BinSearch.h" using namespace std; int main(void) { IntArrayType intArray; int number, pos; generateArray (intArray, MAXINDEX); // generate sorted integer array cout > number; pos = binarySearch(intArray, O, MAXINDEX - 1, number); if(pos == -1) cout "; for (k = 0; k

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions