Форум языка CPP

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Форум языка CPP » Код домашнего задания » Рекурсивно двоичный поиск


Рекурсивно двоичный поиск

Сообщений 1 страница 2 из 2

1

Код:
//////////////////////////////////////////////////////////////////////////////////
/*
*Function search of array
*/
//////////////////////////////////////////////////////////////////////////////////
int Function_Search_PPointer(const int *pP, const int iSIZE_I, const int iSearch, const int iStartSIZE)
{
    int iNewSIZE = (iStartSIZE + iSIZE_I) / 2; //Set the search index
        
    if(pP[iNewSIZE] == iSearch)//If the number is found, return its index
    {
    	return iNewSIZE;
    }

    if (iNewSIZE == iSIZE_I || iNewSIZE == iStartSIZE)//If no such number, returns an error message
    {
    	return -1;
    }
    //If you found the number is less than desired, increasing the search index
    //Maximum index plus the index stops divide into two
    if (pP[iNewSIZE] < iSearch)
    {
    	Function_Search_PPointer(pP, iSIZE_I, iSearch, iNewSIZE);
    }
    else //If you found a number greater than desired, continue to divide the search index
    {
    	Function_Search_PPointer(pP, iNewSIZE, iSearch);   
        }
}

0

2


Вы здесь » Форум языка CPP » Код домашнего задания » Рекурсивно двоичный поиск