void binaryTree::searchRecursive(int value , node* &curr ){
   if(curr->value == value) {
   	  std::cout<< "found " << value << std::endl;
   	  return;
   }
   else if(curr->value < value) {
   	   searchRecursive(value, curr->right);
   }
   else if (curr->value > value) {
   	  searchRecursive(value, curr->left);
   }
   else
   	std::cout<< value << "not found" <<std::endl;
   	  return;
   
}
int searchRecursive(LPSTR lpszPath, char **filter, int nFilts, int cnt, mxArray *structOut, const char *defaultPath)
{
	int ii, passes;
    WIN32_FIND_DATA WFD;
    HANDLE hSearch;
    CHAR szFilePath[MAX_PATH + 1];
	char defaultPathNew[MAX_PATH + 1];
    PathCombine(szFilePath, lpszPath, "*");
    hSearch = FindFirstFile(szFilePath,&WFD);
    do {
        if(strcmp(WFD.cFileName,"..") && strcmp(WFD.cFileName,"."))
        {
			if(WFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				PathCombine(szFilePath, lpszPath, WFD.cFileName);
				PathCombine(defaultPathNew,defaultPath,WFD.cFileName);
				cnt = searchRecursive(szFilePath, filter, nFilts, cnt, structOut, &defaultPathNew);
			}
		}
		passes = 0;
		for (ii = 0; ii < nFilts; ii++) {
			if (wildcmp(filter[ii],WFD.cFileName)){
				passes = 1;
				break;
			}
		}
		if (passes){
			addResultsEntry(WFD, cnt, structOut, defaultPath);
			cnt++;
		}
    } while (FindNextFile(hSearch,&WFD));
    FindClose(hSearch);
    return(cnt);
}
示例#3
0
BinaryTreeNode<T> *BinarySearchTree<T>::searchRecursive(T data, BinaryTreeNode<T> *node){
    if(node){
        if(data < node->getData()){
            return searchRecursive(data, node->getLeft());
        }

        else if(data > node->getData()){
            return searchRecursive(data, node->getRight());
        }

            //data matches current node
        else{
            return node;
        }
    }

    else{
        return node;
    }
};
示例#4
0
文件: Main.cpp 项目: gigte/nlfix
int main(int argc, char *argv[])
{
	if (argc < 2)
	{
		return error(
			"usage: [path] [extensions]\n"
			"\tOR [filename]\n"
			//"usage: [filenames]\n"
			//"\tOR [path] -ext [extensions]\n"
			"Available options are: \n"
			"  -mode         EOL mode (unix, dos, mac)\n"
			"  -skiperrors   skip any errors when processing files\n"
			"  -nolog        hide logs (can increase speed)"
			// TODO:
			//"  -depth        max directory depth (-1 by default)\n"
			//"  -b            make backups\n"
			//"  -bext         backup extension (\"bak\" by default)\n"
			//"  -bdir         backup directory\n"

			//"  -perf         output processing time\n"
		);
	}

	if (processArgs(argc, argv))
		return 1;

	if (!createTempFile())
		return error("failed to create a temporary file");

	int res = 0;

	if (SearchFiles)
	{
		res = searchRecursive(searchpath, extensions);
	}
	else
	{
		if (!processFile(searchpath))
			res = error("unable to open file");
	}

	deleteTempFile();

	return res;
}
示例#5
0
BinaryTreeNode<T> *BinarySearchTree<T>::search(T data){
    searchRecursive(data, root);
};
void binaryTree::search(int key)
{
  return searchRecursive(key,root);
}
void mexFunction(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[])
{
	// Declare variables
	char **fieldnames[NUMBER_OF_FIELDS];
	char *dir, *temp, *fn;
	char **filter[MAX_NUM_FILTERS];
	int ii, jj, nFilts = 0, isRecursive = 0, nCells = 0;
	int hasDir = 0, hasRec;
	const mxArray *aC, *C, *structOut, **ms, **ma;
	int cnt = 0;
	char *defaultPath = "";
	char path[MAX_PATH+1];
	char path2[MAX_PATH+1];
	fileparts parts;
	
	// Set Field Names
	fieldnames[0] = "name";
	fieldnames[1] = "date";
	fieldnames[2] = "bytes";
	fieldnames[3] = "isdir";
	fieldnames[4] = "datenum";
	
	// Parse inputs
	for (ii = 0; ii < nrhs; ii++)
	{
		aC = prhs[ii];
		if (mxIsCell(aC)) {
			nCells = mxGetNumberOfElements(aC);
			for (jj = 0; jj < nCells; jj++)
			{
				C = mxGetCell( aC , jj);
				{PARSE_CHARS(C);}
			}
		} else {
			{PARSE_CHARS(aC);}
		}
	}
	
	// Default path
	if (!hasDir)
	{ 
		getcwd(path, MAX_PATH);
		dir = path;
	}
	
	// Default filter
	if (nFilts == 0) {
		nFilts = 1;
		filter[0] = "*";
	}
	
	// Handle Relative Paths
	if (!strstr(dir,":")) {
		getcwd(path2, MAX_PATH);
		dir = strcat( strcat(path2, "\\") ,dir);
	}
	
	// Make the output structure
	structOut = mxCreateStructMatrix(MAX_FILES, 1, NUMBER_OF_FIELDS, fieldnames);
	
	// Search
	if (isRecursive){
		cnt = searchRecursive(dir,filter,nFilts,cnt,structOut,defaultPath);
	} else {
		cnt = search(dir,filter,nFilts,cnt,structOut,defaultPath);
	}
	
	// Trim off excess and pass it out
	ms = mxGetData(structOut);
	ma = mxMalloc(cnt*NUMBER_OF_FIELDS*sizeof(ms));
	for( ii=0; ii<cnt*NUMBER_OF_FIELDS; ii++ ) {
		ma[ii] = ms[ii];
	}
	mxFree(ms);
	mxSetData(structOut,ma);
	mxSetM(structOut,cnt);
	plhs[0] = structOut;
    return 0;
}