• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 03:44
CEST 09:44
KST 16:44
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Balance hotfix patch 5.0.16b (July 16)56Reynor: GSL Loss Wasn't About Preparation Format16[IPSL] Spring 2026 Grand Finals - This Weekend!7Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) [D] Wireframe Casting Removed Clem: "I don't have that much hope in Blizzard" Reynor: GSL Loss Wasn't About Preparation Format Is the larve respawn broken?
Tourneys
Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
BW General Discussion ASL22 General Discussion NaDa’s Body Followup Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) Etiquete rules in Asl?
Tourneys
[IPSL] Spring 2026 Grand Finals - This Weekend! [Megathread] Daily Proleagues Escore Tournament - Season 3 Small VOD Thread 2.0
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread General RTS Discussion Thread Beyond All Reason
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread The Games Industry And ATVI UK Politics Mega-thread YouTube Thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Req][Books] Good Fantasy/SciFi books Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
ASL S22 English Commentary…
namkraft
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 6913 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 16m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft843
SortOf 102
StarCraft: Brood War
Larva 222
NaDa 147
910 87
sorry 85
GoRush 51
JulyZerg 45
Purpose 10
Dota 2
NeuroSwarm215
League of Legends
JimRising 679
Counter-Strike
Sick112
Other Games
summit1g6570
XaKoH 201
Organizations
Other Games
gamesdonequick2345
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH607
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2219
League of Legends
• Stunt632
Upcoming Events
RSL Revival
1h 16m
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
2h 16m
OSC
5h 16m
IPSL
8h 16m
Bonyth vs Ret
WardiTV Weekly
1d 3h
Monday Night Weeklies
1d 8h
OSC
1d 16h
PiGosaur Cup
2 days
The PondCast
3 days
Replay Cast
4 days
[ Show More ]
CrankTV Team League
4 days
Replay Cast
4 days
CrankTV Team League
5 days
Korean StarCraft League
5 days
RSL Revival
6 days
Online Event
6 days
Replay Cast
6 days
Liquipedia Results

Completed

YSL S3
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Eternal Conflict S2 E3
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Stake Ranked Episode 4
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
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.