Friday, 15 August 2014

[C++]How to use std::stack to deal with the file/directory hierarchy? -



[C++]How to use std::stack to deal with the file/directory hierarchy? -

i have 3 class, root, cfile, subdirectory. root abstract class. cfile , subdirectory derived root. cfile has attributes: name:string , size:int, level:int. subdirectory has attributes: name:string, size:int, level:int,a vector, contains both files , directories , function void add() force file or directory vector. if file in directory, file's level higher directory's one. setters , getters defined.

now, have file called dirread.h can struct entries in current diretory (computer's folder). each entry has filename, size, level , type (either file or directory). in main function, i'm asked utilize info dirread input build hierarchy of file scheme (using cfile , subdirectory). dirread.h conducts pre-order triversal. recursion not accepted in case (i tried, , dirread.h reported error). i'm asked utilize stack deal input, don't know how. apparently level of import here. have tried create stack , force files , directories stack, compare level form hierarchy. root doesn't have add together function, there's no way add together cfile subdirectory because root*. knows how this? thx.

you utilize stack maintain track of directories haven't explored yet. can utilize next algorithm:

push root directory onto stack.

pop top entry off stack. if stack empty, stop, you're done.

traverse directory pulled off stack. add together every file , directory in info structure. also, force every directory find onto stack.

go step 2.

c++ stack composite

No comments:

Post a Comment