+ 5
Doubly linked list
I want to create a java GUI program that can open text files and store the directories of the opened files in an array. Then I want a previous and a next button to navigate through the text file. I have been able to search for the text file and I can display the text contained therein but to store the directories of the opened files has been a problem and the previous and next button is not working yet please help me. I think I will use doubly linked list.
2 Réponses
+ 1
Do I understand you correctly that you want a list of filenames through which you want to navigate using next and previous buttons?
Does this list of files change regularly or is it more or less fixed? And if it changes: do you often have to insert files in between others or can you simply add them at the back of the list?
If the list is stable I'd simply use an array. Keep an index variable around that increases (with overflow protection) on next and decreases on previous (with underflow protection).
If the list sometimes changes or it changes regularly but you only have to add to the back I'd use an array based standard container. In C# that would be a list, in C++ a vector. I'm not familiair enough with java to know what such a container is called there.
Only if I find myself regularly adding and removing objects at random places AND I don't often need indexed access to my data (i.e. reading or changing element 1563, etc.) I would consider using a linked list.
+ 1
Thanks @freddy I tried the array and continually change the index as I add file to the array.I used the linked list