ChiefRedBull 02-13-2002, 10:28 AM <h1><font color=orange>Data Structures 2: Stacks and Queues</font></h1><p>
More class modules!!
The first of the two creates a stack structure around a basic VB array. A stack is a LIFO structure, meaning that you can only place in and take out items from one end.
eg - Add two elements
5.
4.
3.
2. element 2
1. element 1
Remove one element
5.
4.
3.
2.
1. element 1
Add two more
5.
4.
3. element 4
2. element 3
1. element 1
So..... you cant take out element 1 until the rest have been removed...
Enjoy it, and expect very soon - Queues.
Undo Implimentation v1.0
Here is an example of a very, very simple undo feature using a slightly modified version of ChiefRedBull's clsStack.cls. Read the comments at the top of the form's code to see what has changed and why. This would have been better off as a reply to his post, but I'm a newbie and can't post there so here it is.
Enjoy,
Orbity
P.S. Watch out for version 2.0 which will also use a "redo" feature
Sorry, forgot the code
You might be thinking... but in a text box I can just right click and choose undo, wrong answer it is different, check it out and let me know what you think. Reason I say this is that is what was said in the forum and I wanted to clear that up for you guys who thought it might be useless, not to mention it was designed to be an example of another way to use this stack, not how to properly impliment an undo feature in your programs :)
ChiefRedBull 03-10-2002, 03:51 PM <h1><font color=orange>Data Structures 2: Queues</font></h1><p>
Sorry this has been so long... I completely forgot about it, and have only just got round to needing one myself. I wrote it, then remembered about you guys... so here it is.
Its a simple queue to store strings. It is dynamic, so you can dimension it at runtime, but you MUST dimension it before you start to use it, or else it will error. Sensible really IMHO.
It *IS* dynamic at runtime, and can be resized, but I haven't programmed in any logic to make sure this runs ok, so its down to you to do the logic. You can check the Queues state using the
.IsEmpty
.IsFull
.Count
.Max
.Front
.Backproperties.
I hope you find it useful!! :D :D
I just downloaded Orbitys example of using my Class and it made my day!! Thats exactly the sort of thing I was hoping to prompt. Its a perfect example of why stacks are useful, and how simple they are to implement. Thankyou Orbity! :D
Undo/Redo Implimentation 2.0
Well I highly doubt anyone was really waiting for it, but here it is anyway :rolleyes:, the update to my implimentation of ChiefRedBull's stack. I have added a Sub to clear the stack and changed the name of the stack since there are 2 seperate versions of the class being used here.
Basicly other than the added Sub the clsRedoStack is otherwise unchanged and the only change to the clsUndoStack was noted in the previous version and is also noted in the comments of this project.
I must admit, I thought this would be really easy, but I did have some newbie difficulty with getting it right. I have tested this with just over 1,000 levels of undo/redo and all seems ok. If anyone finds any bugs or has any suggestions please let me know.
Happy Coding,
Orbity
ChiefRedBull 03-12-2002, 04:02 AM Orbity - thats great! :D
After cosultation with Orbity I have realised that in fact, his code is perfect and does not need any alterations. In my haste I failed to understand correctly what he was doing...silly me. :D
Download it, use it, its great. Actually, I'm gonna use this in my coursework.... and yes, you'll get the credit! Hee hee
Undo/Redo Implimentation 3.0
It has been quite a while and I pretty much forgot about this update. This version brings the example back to using 1 class instead of 2, and this class differs from the original stack class as follows:
Added:
- boolean variable named "Undo"
- sub to clear the stack
- adjust the new "Undo" variable in the Class_Initialize()
- sub to setup the type of stack (undo or redo)
Changed:
- The Pop() function will now react to the type of stack being used by checking the "Undo" boolean variable
This was again tested on 1,000 levels of Undo/Redo but if anyone finds any bugs or has any suggestions please let me know.
Just a side note here, I wouldn't use this for something that would require a large amount of data in a text box because it copies the entire contents of the text box each time the Changed event fires so it would be quite a memory hog if you had all of this data stored in memory many many times over. This is just an example of how it could be done for a small scale app. :D
Happy Coding,
Orbity
|