Skip to content

Instantly share code, notes, and snippets.

@StabbyMcDuck
Created November 10, 2014 02:03
Show Gist options
  • Save StabbyMcDuck/bd4fad0b0f250e852e34 to your computer and use it in GitHub Desktop.
Save StabbyMcDuck/bd4fad0b0f250e852e34 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <string>
//***********************************
// A program to search through 4 different files looking for a number, 5
//***********************************
void insertSort(int arrayToSort[], int arraySize){
for(int i = 1; i < arraySize; i++)
{
int x = arrayToSort[i];
int arrayNumb = arrayToSort[i];
while((i > 0) && (arrayToSort[i-1] > x){
arrayToSort[i] = arrayToSort[i-1];
i--;
}
arrayToSort[i] = x;
}
}
void printArray(int arrayPrint[], int arrayLength){
for(int i = 0; i < arrayLength; i++){
std::cout << arrayPrint[i] << std::endl;
}
}
bool searchBinary(int arrayCheck[], int arrayLength){
int start = 0;
int end = arrayLength - 1;
int middle = ((end - start) / 2);
while((arrayCheck[middle] != 5)){
if(arrayCheck[middle] < 5){
start = middle;
middle = ((end - start)/2) + start;
}if(arrayCheck[middle] > 5){
end = middle;
middle = (end - start)/2) + start;
}else if(end == middle){
break;
}else if(start == middle){
break;
}
}
if(arrayCheck[middle] == 5){
return true;
}else{
return false;
}
}
void hasAFive(){
if(missing == true){
std::cout << "This file has a 5!" << std::endl;
}else{
std::cout << "This file has no 5 :( " << std::endl;
}
}
int main(){
std::ifstream no5File("no5.txt");
std::ifstream earlyFile("early.txt");
std::ifstream middleFile("middle.txt");
std::ifstream endFile("end.txt");
int no5Char;
int earlyChar;
int middleChar;
int endChar;
bool no5Bool = false;
bool earlyBool = false;
bool middleBool = false;
bool endBool = false;
int arraySize = 20;
int no5[arraySize];
int early[arraySize];
int middle[arraySize];
int end[arraySize];
for(int = 0; i < arraySize; i++){
no5Bool >> no5Char;
if(no5Char = 5){
no5Bool = true;
}
no5[i] = no5Char;
}
void hasAFive();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment