We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › About data structures
Page Index Toggle Pages: 1
About data structures (Read 1577 times)
About data structures
Jul 2nd, 2009, 3:44am
 
Hello all,how to build a Queue in PDE?Or would you recommend some references about building data structures in PDE?Thank you.
Re: About data structures
Reply #1 - Jul 2nd, 2009, 4:55am
 
As processing is 100% JAVA they are still there:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Queue.html
Re: About data structures
Reply #2 - Jul 2nd, 2009, 4:57am
 
Hi,

A basic first-in-first-out queue of numbers to get you started Smiley

Code:

// Create a Queue
LinkedList queue = new LinkedList();

// Put some numbers in it
// Each number is added at the end of the Queue.
queue.offer(1);
queue.offer(2);
queue.offer(3);

// get the first element, as an int
int element = (Integer) queue.pop();
println(element);


as for data structures: they are called Objects. See here http://processing.org/learning/objects/

alvaro
Re: About data structures
Reply #3 - Jul 2nd, 2009, 5:09am
 
hey eskimo wassup?
anyways LinkedList implements Queue, and is afaic the easiest to get started with, but of course you may choose another implementation, depending on what you want to do (multithreading, fixed number of elements, alternative ordering)
yeah
Reply #4 - Jul 3rd, 2009, 4:22am
 
Thank you!It works!
And how about the declaration of "Queue q;"?It seems also valid,but how to initialize it,say,give its initial value,in the form like "ArrayList al=new ArrayList()"?
Thank you for reply. Smiley
Re: About data structures
Reply #5 - Jul 3rd, 2009, 5:02am
 
Queue is an Interface. It's like a template for a family of classes. But you can't initialise an interface, you have to choose one of the implementing classes. Java comes with a number of classes that implement Queue, but LinkedList is the most general purpose one I think.
Page Index Toggle Pages: 1