1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/**
Name: William Lee
Compiler: GNU GCC Compiler
Assignment #2
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void insertionSort(string[], string[], int, int);
void showArray(string[], string[], int, int);
void binarySearch(const int[], int, int);
void output(ofstream, string[], int);
int main(){
ifstream infile1, infile2;
ofstream outfile;
infile1.open("keywords.txt");
infile2.open("unsorted_dictionary.txt");
outfile.open("output.txt");
const int SIZE1 = 84;
const int SIZE2 = 16000;
string unsorted_dictionary[SIZE1], keywords[SIZE2];
int index1 = 0, index2 = 0;
if (infile1 && infile2){
while(!infile1.eof() && !infile2.eof()){
infile1 >> keywords[index1];
infile2 >> unsorted_dictionary[index2];
index1++;
index2++;
insertionSort(keywords, unsorted_dictionary, index1, index2);
output(outfile, unsorted_dictionary, index2);
outfile.close();
return 0;
}
cout << "Values Assigned In The Arrays!";
}
else
cout << false;
return 0;
}
void insertionSort(string arr1[], string arr2[], int ind1, int ind2){
{
int i, j, k, l;
string tmp1, tmp2;
for (i = 1; i < ind1; i++) {
j = i;
while (j > 0 && arr1[j - 1] > arr1[j]) {
tmp1 = arr1[j];
arr1[j] = arr1[j - 1];
arr1[j - 1] = tmp1;
j--;
}
}
for (k = 1; i < ind2; k++) {
l = k;
while (l > 0 && arr1[l - 1] > arr1[l]) {
tmp2 = arr1[l];
arr1[l] = arr1[l - 1];
arr1[l - 1] = tmp2;
l--;
}
}
}
}
void output(ofstream outputting, string array[], int length = 0){
outputting << "Keyword not found: " << array[length] << endl;
length++;
outputting << "Number of Keywords not Found == 20";
}
void binarySearch(const int array[], int numElems, int value){
int first = 0,
last = numElems - 1,
middle,
position = -1;
bool found = false;
while (!found && first <= last){
middle = (first + last) / 2;
if(array[middle] == value){
found = true;
position = middle;
}
else if (array[middle] > value)
last = middle - 1;
else
first = middle +1;
}
}
|