hello all, great to see you all here so active. it's my first time writing in here. is there a way to create a Stack? or still no? I might wanna hold some sets of values for later use on a stack-style system but if there are still no such thing in ChucK (and probably, not suitable for its programming style), i might consider using an Array (with limited size) for the task instead. thanks & take care all. - kij
Hi Kijjasak, Yes, there is no stack functionality in ChucK at the moment. Your best option now is to use an array, although in the future native ChucK arrays will likely support push and pop stack operations. spencer On Dec 10, 2006, at 4:41 PM, kijjasak triyanond wrote:
hello all, great to see you all here so active. it's my first time writing in here.
is there a way to create a Stack? or still no? I might wanna hold some sets of values for later use on a stack- style system but if there are still no such thing in ChucK (and probably, not suitable for its programming style), i might consider using an Array (with limited size) for the task instead.
thanks & take care all. - kij _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Spencer Salazar wrote:
Hi Kijjasak, Yes, there is no stack functionality in ChucK at the moment. Your best option now is to use an array, although in the future native ChucK arrays will likely support push and pop stack operations.
Well, or naturally you can write your own stack. Here's a simple integer stack: class IntStack { class Item { 0 => int value; Item @ below; } new Item @=> Item @ bottom; bottom @=> Item top; fun void push(int value) { new Item @=> Item @ item; value => item.value; top @=> item.below; item @=> top; } fun int pop() { top.value => int value; if(top != bottom) { top.below @=> top; } return value; } fun int isEmpty() { return top == bottom; } } Then the following code: IntStack stack; stack.push(1); stack.push(2); stack.push(3); stack.push(4); stack.push(5); while(!stack.isEmpty()) { <<< stack.pop() >>>; } Produces: 5 :(int) 4 :(int) 3 :(int) 2 :(int) 1 :(int) -Scott
participants (3)
-
kijjasak triyanond
-
Scott Wheeler
-
Spencer Salazar