This is an alternative, simpler, more encapsulated implementation of Ammorth's LinkedList. A lot of credit for Lists should go to Ammorth since the library is based on his work, as he made his library more powerful and more complex I was working in the other direction to create a slightly more limited, but simpler library. I think both approaches have their merits, so I am now finally submitting my version as well.
Originally, this submission was split up into two data structures, stacks and lists, however they were similar enough that I ended up merging them into one script that can function as either of the two.
//*  a stack and a simple linked list.
//*  this to become a problem.
//*  All stack methods are of course O(1) and as fast as possible.
//*  If you just need a stack, this is definitely the best choice.
//*   set s=Stack.create()  - Instanceates a new Stack object.
//*   call s.destroy()      - Destroys the Stack.
//*   call s.push(123)      - Pushes the value 123 on the stack.
//*                           instances of the same value.
//*                           and stores it to the variable i.
//*   s.peek()==Stack.EMPTY - Checks if the stack is empty.
//*   call s.add(123)       - Adds the value 123 to the list.
//*   s.size                - The total number of values on the list.
//*   s.contains(123)       - Checks if the value 123 is on the list.
//*                           123 is on the list to the variable n.
//*                           the value was not found on the list.
//*                           values that were removed.
//*                           it to the variable s2.
//*                           the Enum function interface.
// Use a totally random number here, the more improbable someone uses it, the better.
// This is the value that is returned by .pop and .peek methods and .first and .random operators when called on an empty stack.
// Get an index from the list of free indexes.
// Extend the list of free indexes if needed.
// Store the value to the index.
// Add index to the top of the stack.
// Get the top index of stack.
// Safety check in case a user pops an empty stack.
// Remove the top index from stack.
// Add the index to the list of free indexes.
// Read the value of the top index.
// Get the first index of the list.
// Search through the list.
// Stop the search when the end of the list is reached.
// Stop the search if the value is found.
// Get the next index of the list.
// Increase the count if the value is found.
// Loop through the list.
// Stop the loop after a random amount of repeats.
// Check if the first index holds the value.
// Search through the rest of the list.
// Check if the next index holds the value.
// Remove the index from the stack.
// Add the removed index to the list of free indexes.
// If the first index holds the value, pop it.
// If the list is empty, return.
// Repeat until the first index doesn't hold the value.
// Call the Enum function for each value in the array.
// Enumerate in which direction?
// Add a dummy index to the top of the new list.
// Get an index from the list of free indexes and add it at the end of the list.
// Copy the value to the new index.
// End the new list correctly.
// Remove the dummy index.
// Copy the size value to the new list.
// Remove all remaining indexes from the stack.
// Get the top index.
// Remove it from the stack.
// Add it to the list of free indexes.
// Store the EMPTY value to index 0 to make .peek inline friendly.
Last edited by Anitarf : 08-11-2009 at 12:27 AM.
it allows to store only integers ?
Why would you need to store anything other than integers?
i don't see any sense to make "store systems" not as textmacro.
or you wrote this for your own use and decided to post it here ?
Well, TimerUtils is widely used and it can only store integers as well. I don't see the problem with that.
I don't see any sense to make any system as textmacro.
// Add a value to the list.
I suppose I figured it was necessary to store 'value' somewhere, in order for this to be useful in any way at all. Maybe I'm wrong.
I see. Weird, I was sure that I tested it. Must have mixed it up with Stacks. Anyway, yeah, the value assigment is missing. Didn't realize that was what you were refering to. Fixed.
EDIT: Oh, I see now. The first link in the list is the handler link, got it.
Last edited by Here-b-Trollz : 06-29-2009 at 07:52 PM.
just a quick suggestion, add .size also to the stack, main reason being that adding it is simply easy, lol.
"In a way, we're all troubled adolescent girls... deep inside."
I would consider the lack of .size a feature.
My new signature - Now easier to understand than ever!