• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 19:53
CET 00:53
KST 08:53
  • 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
ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
Weekly Cups (March 9-15): herO, Clem, ByuN win02026 KungFu Cup Announcement5BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains17Weekly Cups (March 2-8): ByuN overcomes PvT block5
StarCraft 2
General
Potential Updates Coming to the SC2 CN Server Weekly Cups (March 2-8): ByuN overcomes PvT block Blizzard Classic Cup - Tastosis announced as captains Weekly Cups (March 9-15): herO, Clem, ByuN win GSL CK - New online series
Tourneys
2026 KungFu Cup Announcement [GSL CK] #2: Team Classic vs. Team Solar [GSL CK] #1: Team Maru vs. Team herO RSL Season 4 announced for March-April PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar)
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
The PondCast: SC2 News & Results Mutation # 517 Distant Threat Mutation # 516 Specter of Death Mutation # 515 Together Forever
Brood War
General
ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/ Gypsy to Korea BSL 22 Map Contest — Submissions OPEN to March 10 Are you ready for ASL 21? Hype VIDEO
Tourneys
ASL Season 21 Qualifiers March 7-8 [Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours IPSL Spring 2026 is here!
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Zealot bombing is no longer popular?
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Path of Exile Nintendo Switch Thread PC Games Sales Thread
Dota 2
Official 'what is Dota anymore' discussion 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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Mexico's Drug War Russo-Ukrainian War Thread NASA and the Private Sector
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread Tokyo Olympics 2021 Thread Formula 1 Discussion General nutrition recommendations Cricket [SPORT]
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 4381 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 7m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft366
SpeCial 209
SteadfastSC 131
ProTech35
StarCraft: Brood War
GuemChi 1455
Artosis 598
Nal_rA 62
Britney 0
Dota 2
monkeys_forever490
League of Legends
JimRising 595
Super Smash Bros
hungrybox504
C9.Mang0248
AZ_Axe92
PPMD43
Other Games
summit1g13937
shahzam438
Maynarde115
Trikslyr81
ViBE33
Mew2King26
Organizations
Other Games
gamesdonequick647
Dota 2
PGL Dota 2 - Main Stream338
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• davetesta2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Eskiya23 20
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• Scarra1508
• imaqtpie1173
Upcoming Events
Replay Cast
7m
CranKy Ducklings6
WardiTV Team League
12h 7m
PiGosaur Cup
1d
Kung Fu Cup
1d 11h
OSC
2 days
The PondCast
2 days
KCM Race Survival
2 days
WardiTV Team League
2 days
Replay Cast
3 days
KCM Race Survival
3 days
[ Show More ]
WardiTV Team League
3 days
Korean StarCraft League
4 days
RSL Revival
4 days
Maru vs Zoun
Cure vs ByuN
uThermal 2v2 Circuit
4 days
BSL
4 days
RSL Revival
5 days
herO vs MaxPax
Rogue vs TriGGeR
BSL
5 days
Replay Cast
6 days
Replay Cast
6 days
Afreeca Starleague
6 days
Sharp vs Scan
Rain vs Mong
Wardi Open
6 days
Monday Night Weeklies
6 days
Liquipedia Results

Completed

Proleague 2026-03-15
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Jeongseon Sooper Cup
BSL Season 22
CSL Elite League 2026
RSL Revival: Season 4
Nations Cup 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
NationLESS Cup
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 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.