• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 18:07
CEST 00:07
KST 07:07
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro4 Preview: On Course10Code S Season 1 - RO8 Preview7[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16
Community News
Maestros of The Game 2 announcement and schedule !10Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event12Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25
StarCraft 2
General
Code S Season 1 - RO8 Preview Behind the Blue - Team Liquid History Book Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Code S Season 1 (2026) - RO12 Results
Tourneys
Maestros of The Game 2 announcement and schedule ! 2026 GSL Season 2 Qualifiers SC2 INu's Battles#16 <BO.9> Master Swan Open (Global Bronze-Master 2) GSL Code S Season 1 (2026)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players
External Content
Mutation # 525 Wheel of Misfortune The PondCast: SC2 News & Results Mutation # 524 Death and Taxes Mutation # 523 Firewall
Brood War
General
Flashes ASL S21 Ro8 Review ASL Tickets to Live Event Finals? [ASL21] Ro4 Preview: On Course Quality of life changes in BW that you will like ? Why there arent any 256x256 pro maps?
Tourneys
[ASL21] Semifinals A [Megathread] Daily Proleagues [BSL22] RO16 Group Stage - 02 - 10 May [ASL21] Ro8 Day 3
Strategy
[G] Hydra ZvZ: An Introduction Simple Questions, Simple Answers Fighting Spirit mining rates Muta micro map competition
Other Games
General Games
Warcraft III: The Frozen Throne Stormgate/Frost Giant Megathread PC Games Sales Thread Path of Exile Nintendo Switch Thread
Dota 2
The Story of Wings Gaming
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
YouTube Thread US Politics Mega-thread Russo-Ukrainian War Thread UK Politics Mega-thread European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
How EEG Data Can Predict Gam…
TrAiDoS
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2534 users

The Big Programming Thread - Page 260

Forum Index > General Forum
Post a Reply
Prev 1 258 259 260 261 262 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-03-03 17:25:14
March 03 2013 17:22 GMT
#5181
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?
Isualin
Profile Joined March 2011
Germany1903 Posts
Last Edited: 2013-03-03 17:40:13
March 03 2013 17:39 GMT
#5182
I can recommend cs101 course in Udacity to beginners(you will use python to build a basic crawler, search engine and pageranker) In school, our homeworks were matrix multiplication, transposing, search algorithms, data structures, multithreading and stuff like that. I did not understand how and when to use them at first. But creating something useful from the bottom up and using those structures to do that is a much more fun approach.
| INnoVation | The literal god TY | ByuNjwa | LRSL when? |
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-03-03 18:44:05
March 03 2013 18:42 GMT
#5183
On March 04 2013 02:39 Isualin wrote:
I can recommend cs101 course in Udacity to beginners(you will use python to build a basic crawler, search engine and pageranker) In school, our homeworks were matrix multiplication, transposing, search algorithms, data structures, multithreading and stuff like that. I did not understand how and when to use them at first. But creating something useful from the bottom up and using those structures to do that is a much more fun approach.

I'd want to learn python gui programming but I don't want to bother with a web crawler. I can already do that in other languages. That course seems too specific.

I think there's a push for personalized learning right now.
Sorry to hijack.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
LukeNukeEm
Profile Joined February 2012
31 Posts
March 03 2013 20:22 GMT
#5184
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority
Show nested quote +

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:
Show nested quote +

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
March 03 2013 21:20 GMT
#5185
On March 04 2013 05:22 LukeNukeEm wrote:
Show nested quote +
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)
Gold isn't everything in life... you need wood, too!
LukeNukeEm
Profile Joined February 2012
31 Posts
March 03 2013 21:55 GMT
#5186
On March 04 2013 06:20 MisterD wrote:
Show nested quote +
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"
delHospital
Profile Blog Joined December 2010
Poland261 Posts
March 03 2013 22:04 GMT
#5187
On March 04 2013 06:55 LukeNukeEm wrote:
Show nested quote +
On March 04 2013 06:20 MisterD wrote:
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"

It's as if someone asked what to eat for breakfast and you answered "I think barbed wire would taste quite well". There is no need to explain why it's a bad idea, and you are the one who should feel bad for the terrible suggestion.
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
March 03 2013 22:22 GMT
#5188
On March 04 2013 07:04 delHospital wrote:
Show nested quote +
On March 04 2013 06:55 LukeNukeEm wrote:
On March 04 2013 06:20 MisterD wrote:
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"

It's as if someone asked what to eat for breakfast and you answered "I think barbed wire would taste quite well". There is no need to explain why it's a bad idea, and you are the one who should feel bad for the terrible suggestion.

I think breakfast is a lot simpler than data structures.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2013-03-03 22:31:20
March 03 2013 22:30 GMT
#5189
Snippet from the output of the prototype primitive messaging system over TCP/IP that I am currently working on:

Hello World!
Hello!
Exception in thread "messaging.Receiver" Exception in thread "messaging.ServerSocketListener" Exception in thread "messaging.Sender" java.lang.Error: java.lang.InterruptedException
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1116)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2052)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at messaging.Sender.run(Sender.java:25)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
... 2 more
java.lang.Error: java.net.SocketException: socket closed
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1116)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.net.SocketException: socket closed
at java.net.DualStackPlainSocketImpl.accept0(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:121)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:183)
at java.net.ServerSocket.implAccept(ServerSocket.java:522)
at java.net.ServerSocket.accept(ServerSocket.java:490)
at messaging.ServerSocketListener.run(ServerSocketListener.java:24)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
... 2 more
java.lang.Error: java.io.EOFException
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1116)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2571)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1315)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at messaging.Receiver.run(Receiver.java:27)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
... 2 more
http://www.fimfiction.net/user/Treasure_Chest
tec27
Profile Blog Joined June 2004
United States3702 Posts
March 03 2013 23:28 GMT
#5190
What exactly do you expect us to do with that? You have an exception somewhere in some mysterious code you haven't given us. We're not wizards.
Can you jam with the console cowboys in cyberspace?
Abductedonut
Profile Blog Joined December 2010
United States324 Posts
March 03 2013 23:53 GMT
#5191
On March 04 2013 08:28 tec27 wrote:
What exactly do you expect us to do with that? You have an exception somewhere in some mysterious code you haven't given us. We're not wizards.


He's probably posting it because it's funny. Relax. Not everyone here is looking for help.
Frigo
Profile Joined August 2009
Hungary1023 Posts
March 04 2013 00:05 GMT
#5192
Yep that's right, it's just for fun.

Also a fun fact: the only way to interrupt a read from a socket's input stream is to close the socket from another thread, and catch the resulting EOFException. It does not react to .interrupt() and thus neither to ExecutorService's shutdownNow().

I'm heading to a java.nio solution asap.
http://www.fimfiction.net/user/Treasure_Chest
phar
Profile Joined August 2011
United States1080 Posts
Last Edited: 2013-03-04 00:11:31
March 04 2013 00:10 GMT
#5193
On March 04 2013 07:04 delHospital wrote:
Show nested quote +
On March 04 2013 06:55 LukeNukeEm wrote:
On March 04 2013 06:20 MisterD wrote:
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"

It's as if someone asked what to eat for breakfast and you answered "I think barbed wire would taste quite well". There is no need to explain why it's a bad idea, and you are the one who should feel bad for the terrible suggestion.



Linked lists (10, to be specific) would actually be a good solution if you only have a small range of possible priorities. Since you only have 10 levels of priority and not an arbitrarily large range, bucket sort becomes your best friend. By using a linked list with head and tail pointers you can completely sidestep the issue of O(n) insertion by just having 10 linked lists, one per priority. You get O(10) worst-case removal, O(10) worst-case insertion. Conversely, a single heap would get you O(log(n)) insertion and removal, which is worse for basically all cases once your data set gets not-tiny.

Things get a bit trickier if this has to support much larger data sets.

But, for this specific problem, don't dismiss the linked list out of hand.



And of course, for the general case of a priority queue with many different levels, a heap is going to be better: http://en.wikipedia.org/wiki/Priority_queue#Usual_implementation
Who after all is today speaking about the destruction of the Armenians?
LukeNukeEm
Profile Joined February 2012
31 Posts
March 04 2013 00:22 GMT
#5194
On March 04 2013 09:10 phar wrote:
Show nested quote +
On March 04 2013 07:04 delHospital wrote:
On March 04 2013 06:55 LukeNukeEm wrote:
On March 04 2013 06:20 MisterD wrote:
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"

It's as if someone asked what to eat for breakfast and you answered "I think barbed wire would taste quite well". There is no need to explain why it's a bad idea, and you are the one who should feel bad for the terrible suggestion.



Linked lists (10, to be specific) would actually be a good solution if you only have a small range of possible priorities. Since you only have 10 levels of priority and not an arbitrarily large range, bucket sort becomes your best friend. By using a linked list with head and tail pointers you can completely sidestep the issue of O(n) insertion by just having 10 linked lists, one per priority. You get O(10) worst-case removal, O(10) worst-case insertion. Conversely, a single heap would get you O(log(n)) insertion and removal, which is worse for basically all cases once your data set gets not-tiny.

Things get a bit trickier if this has to support much larger data sets.

But, for this specific problem, don't dismiss the linked list out of hand.



And of course, for the general case of a priority queue with many different levels, a heap is going to be better: http://en.wikipedia.org/wiki/Priority_queue#Usual_implementation

BARBED WIRE (yes i am butthurt)
gyth
Profile Blog Joined September 2009
657 Posts
Last Edited: 2013-03-04 00:30:03
March 04 2013 00:28 GMT
#5195
how is a linked list a good idea to implement a priority queue x.x

With a finite number of priorities, and a linked list for each, all functions would be constant time.

P.S. phar too fast
The plural of anecdote is not data.
phar
Profile Joined August 2011
United States1080 Posts
March 04 2013 00:29 GMT
#5196
On March 04 2013 09:22 LukeNukeEm wrote:
Show nested quote +
On March 04 2013 09:10 phar wrote:
On March 04 2013 07:04 delHospital wrote:
On March 04 2013 06:55 LukeNukeEm wrote:
On March 04 2013 06:20 MisterD wrote:
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"

It's as if someone asked what to eat for breakfast and you answered "I think barbed wire would taste quite well". There is no need to explain why it's a bad idea, and you are the one who should feel bad for the terrible suggestion.



Linked lists (10, to be specific) would actually be a good solution if you only have a small range of possible priorities. Since you only have 10 levels of priority and not an arbitrarily large range, bucket sort becomes your best friend. By using a linked list with head and tail pointers you can completely sidestep the issue of O(n) insertion by just having 10 linked lists, one per priority. You get O(10) worst-case removal, O(10) worst-case insertion. Conversely, a single heap would get you O(log(n)) insertion and removal, which is worse for basically all cases once your data set gets not-tiny.

Things get a bit trickier if this has to support much larger data sets.

But, for this specific problem, don't dismiss the linked list out of hand.



And of course, for the general case of a priority queue with many different levels, a heap is going to be better: http://en.wikipedia.org/wiki/Priority_queue#Usual_implementation

BARBED WIRE (yes i am butthurt)

What?
Who after all is today speaking about the destruction of the Armenians?
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-03-04 03:02:51
March 04 2013 02:58 GMT
#5197
On March 04 2013 09:29 phar wrote:
Show nested quote +
On March 04 2013 09:22 LukeNukeEm wrote:
On March 04 2013 09:10 phar wrote:
On March 04 2013 07:04 delHospital wrote:
On March 04 2013 06:55 LukeNukeEm wrote:
On March 04 2013 06:20 MisterD wrote:
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"

It's as if someone asked what to eat for breakfast and you answered "I think barbed wire would taste quite well". There is no need to explain why it's a bad idea, and you are the one who should feel bad for the terrible suggestion.



Linked lists (10, to be specific) would actually be a good solution if you only have a small range of possible priorities. Since you only have 10 levels of priority and not an arbitrarily large range, bucket sort becomes your best friend. By using a linked list with head and tail pointers you can completely sidestep the issue of O(n) insertion by just having 10 linked lists, one per priority. You get O(10) worst-case removal, O(10) worst-case insertion. Conversely, a single heap would get you O(log(n)) insertion and removal, which is worse for basically all cases once your data set gets not-tiny.

Things get a bit trickier if this has to support much larger data sets.

But, for this specific problem, don't dismiss the linked list out of hand.



And of course, for the general case of a priority queue with many different levels, a heap is going to be better: http://en.wikipedia.org/wiki/Priority_queue#Usual_implementation

BARBED WIRE (yes i am butthurt)

What?

HE SAID: BARBED WIRE (YES IM BUTTHURT)
It has to do with the discussion earlier in your quote.

Btw I am increasingly afraid of the effects of torrenting. I don't know where else to ask. Yahoo answers isn't techy enough and stackoverflow would probably not condone this kind of information.
If someone were to do it, what benefits does being behind a vpn provide?
Is my download speed slower? Due to encryption.
Will bandwith throttling still occur? ISP finds out you are uploading a lot and therefore caps your download speed or delivers bad ping.

VPNs seem expensive so I'm reluctant to get one and would like to ask the quick question in case anyone knows.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
phar
Profile Joined August 2011
United States1080 Posts
March 04 2013 04:04 GMT
#5198
On March 04 2013 11:58 obesechicken13 wrote:
Show nested quote +
On March 04 2013 09:29 phar wrote:
On March 04 2013 09:22 LukeNukeEm wrote:
On March 04 2013 09:10 phar wrote:
On March 04 2013 07:04 delHospital wrote:
On March 04 2013 06:55 LukeNukeEm wrote:
On March 04 2013 06:20 MisterD wrote:
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority

Insert 10000 3
Insert 19444 9
Pop
Insert 10331 3
Pop
Pop
Pop


Output in this case should be:

19444 [comment: highest priority]
10000
103331
-1


If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"

It's as if someone asked what to eat for breakfast and you answered "I think barbed wire would taste quite well". There is no need to explain why it's a bad idea, and you are the one who should feel bad for the terrible suggestion.



Linked lists (10, to be specific) would actually be a good solution if you only have a small range of possible priorities. Since you only have 10 levels of priority and not an arbitrarily large range, bucket sort becomes your best friend. By using a linked list with head and tail pointers you can completely sidestep the issue of O(n) insertion by just having 10 linked lists, one per priority. You get O(10) worst-case removal, O(10) worst-case insertion. Conversely, a single heap would get you O(log(n)) insertion and removal, which is worse for basically all cases once your data set gets not-tiny.

Things get a bit trickier if this has to support much larger data sets.

But, for this specific problem, don't dismiss the linked list out of hand.



And of course, for the general case of a priority queue with many different levels, a heap is going to be better: http://en.wikipedia.org/wiki/Priority_queue#Usual_implementation

BARBED WIRE (yes i am butthurt)

What?

HE SAID: BARBED WIRE (YES IM BUTTHURT)
It has to do with the discussion earlier in your quote.

Btw I am increasingly afraid of the effects of torrenting. I don't know where else to ask. Yahoo answers isn't techy enough and stackoverflow would probably not condone this kind of information.
If someone were to do it, what benefits does being behind a vpn provide?
Is my download speed slower? Due to encryption.
Will bandwith throttling still occur? ISP finds out you are uploading a lot and therefore caps your download speed or delivers bad ping.

VPNs seem expensive so I'm reluctant to get one and would like to ask the quick question in case anyone knows.

Oh sorry, I didn't read the earlier stuff, just read the question and scanned to see linked list & heap specified. Didn't read anything else too carefully.

Your own question wasn't exactly super clear. Also it has nothing to do with programming, you may want to ask that in the tech support section and people may know more. As an aside, all a VPN does is securely transmit all your data to another network before going out to the rest of the internet to serve whatever requests you're doing. It doesn't reduce the amount of bandwidth in any way.
Who after all is today speaking about the destruction of the Armenians?
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
March 04 2013 04:10 GMT
#5199
On March 04 2013 13:04 phar wrote:
Show nested quote +
On March 04 2013 11:58 obesechicken13 wrote:
On March 04 2013 09:29 phar wrote:
On March 04 2013 09:22 LukeNukeEm wrote:
On March 04 2013 09:10 phar wrote:
On March 04 2013 07:04 delHospital wrote:
On March 04 2013 06:55 LukeNukeEm wrote:
On March 04 2013 06:20 MisterD wrote:
On March 04 2013 05:22 LukeNukeEm wrote:
On March 04 2013 02:22 darkness wrote:
[C language]

Okay, so I'm asked to implement a priority queue with time and memory efficiency in mind. Here's a sample of what the program should take as input:
Insert [number, 10000-19999] [priority; 1-10]
Pop <------- to print an available number with the highest priority
[quote]

Output in this case should be:
[quote]

If there's nothing on queue despite using pop, then print -1.

What should I use to achieve this? C structures? Stack but it might not be good I guess?

I think a linked list would work quite well in this case.


how is a linked list a good idea to implement a priority queue x.x

take a look at http://en.wikipedia.org/wiki/Heap_(data_structure)

how is a heap a good idea to implement a priority queue x.x

..
I realize that you are right, but please post reasoning the next time instead of just writing "your solution is shit. mine is better"

It's as if someone asked what to eat for breakfast and you answered "I think barbed wire would taste quite well". There is no need to explain why it's a bad idea, and you are the one who should feel bad for the terrible suggestion.



Linked lists (10, to be specific) would actually be a good solution if you only have a small range of possible priorities. Since you only have 10 levels of priority and not an arbitrarily large range, bucket sort becomes your best friend. By using a linked list with head and tail pointers you can completely sidestep the issue of O(n) insertion by just having 10 linked lists, one per priority. You get O(10) worst-case removal, O(10) worst-case insertion. Conversely, a single heap would get you O(log(n)) insertion and removal, which is worse for basically all cases once your data set gets not-tiny.

Things get a bit trickier if this has to support much larger data sets.

But, for this specific problem, don't dismiss the linked list out of hand.



And of course, for the general case of a priority queue with many different levels, a heap is going to be better: http://en.wikipedia.org/wiki/Priority_queue#Usual_implementation

BARBED WIRE (yes i am butthurt)

What?

HE SAID: BARBED WIRE (YES IM BUTTHURT)
It has to do with the discussion earlier in your quote.

Btw I am increasingly afraid of the effects of torrenting. I don't know where else to ask. Yahoo answers isn't techy enough and stackoverflow would probably not condone this kind of information.
If someone were to do it, what benefits does being behind a vpn provide?
Is my download speed slower? Due to encryption.
Will bandwith throttling still occur? ISP finds out you are uploading a lot and therefore caps your download speed or delivers bad ping.

VPNs seem expensive so I'm reluctant to get one and would like to ask the quick question in case anyone knows.

Oh sorry, I didn't read the earlier stuff, just read the question and scanned to see linked list & heap specified. Didn't read anything else too carefully.

Your own question wasn't exactly super clear. Also it has nothing to do with programming, you may want to ask that in the tech support section and people may know more. As an aside, all a VPN does is securely transmit all your data to another network before going out to the rest of the internet to serve whatever requests you're doing. It doesn't reduce the amount of bandwidth in any way.

Ah good point. I will ask there.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
JeanLuc
Profile Joined September 2010
Canada377 Posts
March 04 2013 06:10 GMT
#5200
to any web devs: is it okay to be coding just html and vanilla js code in this day and age.
If you can't find it within yourself to stand up and tell the truth-- you don't deserve to wear that uniform
Prev 1 258 259 260 261 262 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 1h 53m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SteadfastSC 126
JuggernautJason118
StarCraft: Brood War
Calm 2475
Artosis 208
ggaemo 131
Mong 26
Dota 2
XaKoH 559
monkeys_forever474
NeuroSwarm105
League of Legends
Doublelift6988
tarik_tv5924
JimRising 405
Counter-Strike
fl0m5315
Fnx 1326
Super Smash Bros
PPMD39
Other Games
Grubby4517
summit1g3464
Liquid`RaSZi1736
FrodaN1605
shahzam766
C9.Mang0262
ZombieGrub115
ArmadaUGS109
UpATreeSC44
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 17 non-featured ]
StarCraft 2
• Hupsaiya 52
• Kozan
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• Eskiya23 22
• Azhi_Dahaki17
• Pr0nogo 1
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2458
League of Legends
• imaqtpie2091
• Shiphtur265
Upcoming Events
OSC
1h 53m
CranKy Ducklings
11h 53m
Afreeca Starleague
11h 53m
Light vs Flash
INu's Battles
12h 53m
ByuN vs herO
PiGosaur Cup
1d 1h
Replay Cast
1d 10h
Replay Cast
2 days
The PondCast
2 days
OSC
2 days
Replay Cast
3 days
[ Show More ]
RSL Revival
3 days
OSC
3 days
Korean StarCraft League
4 days
RSL Revival
4 days
BSL
4 days
GSL
5 days
Cure vs TBD
TBD vs Maru
BSL
5 days
Replay Cast
6 days
Liquipedia Results

Completed

CSL 2026 SPRING (S20)
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2

Upcoming

Escore Tournament S2: W7
YSL S3
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
BLAST Bounty Summer 2026: Closed Qualifier
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.