Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 6th, 2005, 11:40 PM   #1
zman2245
Newbie
 
Join Date: Sep 2005
Posts: 2
Rep Power: 0 zman2245 is on a distinguished road
Queue. Array vs Linked List

Hey I was wondering what anyone would recommend? An array or Linked List for implementing a queue.... which performs better and which is easier to implement? Thanks
zman2245 is offline   Reply With Quote
Old Sep 7th, 2005, 6:26 AM   #2
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 137
Rep Power: 0 L7Sqr is an unknown quantity at this point
It doesnt really matter. (I might catch heat for that).
Whatever you are comfortable with is what you should use.
If you want to limit the number of items in the queue an array
of fixed size might make things a little easier with pointers an
modulus division, but the same can be accomplished with a linked list and a count variable. Of course inserting into the middle of a linked list is easier than doing so in an array. I mention that because you dont exclude priority queue in your post and insertions into a priority queue dont always fall at the beginning or end.
What is your application? What are the requirements?
__________________
"...and though our kids are blessed their parents let them shoulder all the blame."
- The Quiet Things That No One Ever Knows [BrandNew]
L7Sqr is offline   Reply With Quote
Old Sep 7th, 2005, 7:08 AM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Generally speaking, a linked list is best for a queue. An array has the disadvantage of being a fixed length; a linked list will take up less memory and can expand to any length your RAM can hold.
Arevos is offline   Reply With Quote
Old Sep 7th, 2005, 8:20 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Link list hands down.... you will have more flexibility.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Sep 7th, 2005, 11:33 AM   #5
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 137
Rep Power: 0 L7Sqr is an unknown quantity at this point
Quote:
a linked list will take up less memory and can expand to any length your RAM can hold.
An array can grow as well, as large as any linked list, and a linked list is not necessarily any smaller (memory-wise) than an array.
__________________
"...and though our kids are blessed their parents let them shoulder all the blame."
- The Quiet Things That No One Ever Knows [BrandNew]
L7Sqr is offline   Reply With Quote
Old Sep 7th, 2005, 11:58 AM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by L7Sqr
An array can grow as well, as large as any linked list, and a linked list is not necessarily any smaller (memory-wise) than an array.
How exactly do you "grow" an array? Do you mean using realloc?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 7th, 2005, 12:02 PM   #7
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
Quote:
Originally Posted by Ooble
How exactly do you "grow" an array? Do you mean using realloc?
a very expensive process, no doubt!
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Old Sep 7th, 2005, 12:09 PM   #8
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by stevengs
a very expensive process, no doubt!
if you do it, let's say, every 10 entries it isn't that expensive. linked lists are handier though, since you can easily remove entries.
Polyphemus_ is offline   Reply With Quote
Old Sep 7th, 2005, 3:40 PM   #9
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 137
Rep Power: 0 L7Sqr is an unknown quantity at this point
Quote:
Do you mean using realloc?
Yes, that is what I meant.
I made no claims about it being the fastest or best method, I was only pointing out that it could be done.
__________________
"...and though our kids are blessed their parents let them shoulder all the blame."
- The Quiet Things That No One Ever Knows [BrandNew]
L7Sqr is offline   Reply With Quote
Old Sep 9th, 2005, 1:14 AM   #10
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
for dynamic sorting and greater flexibility the linked list is definately the way to go.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC