Can any one pls tell me which data structure will best suit the application - notepad.......? Justify as to how its best suited.............
Thanking u in advance....
Printable View
Can any one pls tell me which data structure will best suit the application - notepad.......? Justify as to how its best suited.............
Thanking u in advance....
Binary, so you can't read it? ;)
Is this a homework question? Have you tried GOOGLE?
no ths s not a home work question........
its a question asked in the technical interview for jobs........
i had thought about the data structure 'trie'.........
bt i cld nt obtain a reasonable answer..........
thats why i posted it here...........
I had tried google............bt still was not satisfied............
It will be good to use linked list of fixed sized (may be) arrays of chars for notepad like text handling!
Quote:
Originally Posted by mandeep2
but you will not be able to move around the text while editing.......... it becomes difficult for you right..........?
it should also be convenient for you to move around the text.......?
Xml
what do you mean by simply mentioning as xml?
if you mean a data structure to store the text typed in notepad, than string would no doubt be one of the most (if not the most) suitable data structure for notepad application since notepad basically handles, well.. string.
in many languages string is treated just as other builtin datatypes, making most people think that string is just a primitive datatype like bool, int, or char. The truth is that string is actually a char container, making it practically a data structure. a string implementation can utilise any kind of data structure available (linked list and array being the most simple). Implementation wise, we can leave the worries to the language and library designer and simply use what the language & std. library provide (e.g. std::string on c++, String on java, etc).
just my 2cents
Yes,
Ur suggestion was correct.........
Actually string is also a good one..............
Thanks a lot yere.............
For larger text files, string it not a good solution - for both non-terminated C-style strings or strings which store their length. What if you need to insert some text at the beginning of document (say at 50th character, in a 2MB document). You need to run a loop even for one character insert/delete till 2000000+ counts?
I would recommend using linked list (or std::list), and store each line as list' one element. Each list' element would be 'string' - which you may limit to few KBs. Any replace, insert, delete would be just replacing the string contents for that line. This would, of course, not require whole 'list' object to be traversed.
Now here comes the hard part: when there is line break, or merging of two lines - the two list' elements needs to be merged. Say 6th and 7th lines are merged, you need to append 7th line content into 6th, and delete the 7the line from list. 8th line would now become 7th and so on.
Special taken must be taken care of of multiple lines are being deleted, inserted or replaced - this might be complicated, but appropriate solution.
Similar thing needs to be done where a single line is being breaked into two lines (a simple Enter key would do!).
But if your text-editor would be limited (or you place this limitation) to few KBs, you can straightly use string as data-structure. Remeber Notepad.EXE used to support only 65K files?
I have a problem of what type of data structure of my mobile dictionary application. I use notepad to save data. From my program I call the data that save on notepad. pls help me of what data structures that if I save data as a textfile.