Пример #1
0
int main(int argc, char const *argv[])
{
    int* plSize = new int(0);
    kd_point** pntList = getPointList(std::string("../peptideDatabase.csv"), plSize);

    kd_tree mTree;
    mTree.build(pntList, *plSize);

    // ID,NET,Mass
    // 0,0.149476528,544.2968806
    kd_point* search_point = new kd_point();
    search_point->setObservedMass(544.2968806);
    search_point->setObservedNET(0.149476528);
    search_point->setID(0);

    // 1,0.148264542,609.2944385

    kd_point* sp = new kd_point();
    sp->setObservedMass(609.2944385);
    sp->setObservedNET(0.148264542);
    sp->setID(1);


    mTree.search(search_point);
    mTree.search(sp);


    linSearch(pntList, search_point, plSize);
    linSearch(pntList, sp, plSize);

    return 0;
}
Пример #2
0
size_t AdjacencyList::search(size_t element, size_t begin, size_t end) {
	if(end-begin>10) {
		return binSearch(element,begin,end);
	} else {
		return linSearch(element,begin,end);
	}
}
Пример #3
0
int main() {
	// initialize our variables, including a pointer to the beginning of
	// the array of input integers. 
	// note its size will change as we input more and more numbers

	// we allocate one space for the first integer to be entered into
	int* arr = calloc(1, sizeof(int));
	int* arrCopy;
	int size = 0;
	int searchValsSize = 0;
	int* searchVals = calloc(1, sizeof(int));

	printf("enter numbers to fill an array, entering -999 when finished \n");
	arr = read(arr, &size);
	

	arrCopy = copyArray(size, arr);

	qsort(arrCopy, size, sizeof(int), cmpfunc);

	printf("\nYour array: \n");
	printArr(size, arr);
	printf("\nYour array sorted: \n");
	printArr(size, arrCopy);

	printf("\nEnter a value to search for\n");
	searchVals = read(searchVals, &searchValsSize); 
		


	// for each search value, we pass the value to the search function and report how long it took and where it was
	printf("\nLinear Search Results: \n");
	for(int i =0; i<searchValsSize; i++){

		int* found = linSearch(arr, size, searchVals[i]);

		if(found[0] != -1)
			printf("found %d at position %d by making %d comparasins\n", searchVals[i], found[0], found[1]);
		else
			printf("Did not find %d by making %d comparasins\n", searchVals[i], found[1]);
	}		

	// same thing as before, only now we use the sorted array to search through each time
	printf("\nBinary Search Results: \n");
	for(int i =0; i<searchValsSize; i++){
 
                 int* found = binSearch(arrCopy, size, searchVals[i]);
 
                 if(found[0] != -1)
                         printf("found %d at position %d by making %d comparasins\n", searchVals[i], found[0], found[1]);
                 else
                         printf("Did not find %d by making %d comparasins\n", searchVals[i], found[1]);
         }


	
        return 0;
}
Пример #4
0
void User::PlayOn(bool &fin){ 
    int postion;
    int correct = 0;
    int miss = 0;
    bool tr = true;
    char input;
    int trys = 0;
    do{
    cout<<"Please enter the the letter you would like to try."<<endl;
        cout<<"Remember, you can enter the number 0 any time to quit."<<endl;
        cin>>input;
        if(isalpha(input)){
            if(islower(input))
                input = toupper(input);
            if(trys == 0){
                postion = linSearch(word,sizWord,input);
                if(postion == -1){
                    cout<<"Sorry that letter is incorrect"<<endl;
                    guess[miss] = input;
                    miss++;
                    tr = false;
                }
                else{
                    corrc[postion] = word[postion];
                    cout<<"Yes, that is one of the letters of the word"<<endl;
                    correct++;
                    tr = false;
                }
            }
            else{
                postion = linSearch(guess,miss,input);
                if(postion == -1){
                    postion = linSearch(corrc,sizWord,input);
                    if(postion == -1){
                        postion = linSearch(word,sizWord,input);
                        if(postion == -1){
                            cout<<"Sorry that letter is incorrect"<<endl;
                            guess[miss] = input;
                            miss++;
                            tr = false;
                        }
                        else{
                            corrc[postion] = word[postion];
                            cout<<"Yes, that is one of the letters of the word"<<endl;
                            correct++;
                            tr = false;
                        }
                    }
                    else{
                        cout<<"I'm sorry, but you already guessed that letter";
                        cout<<" correctly.";
                    }  
                }
                else{
                    cout<<"Sorry but you've already used that letter.";
                }
            }    
        }
        else if(input == '0'){
            cout<<"You have entered 0, we will now exit the game."<<endl;
            fin = false;
            tr = false;
            cout<<"This should display"<<fin<<"and "<<tr<<endl;
        }
        else
            cout<<"That is an invaild input, please try again.";
    }while(tr = true);
}