• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 09:14
CET 15:14
KST 23:14
  • 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
Rongyi Cup S3 - Preview & Info3herO wins SC2 All-Star Invitational14SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0
Community News
Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)25Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7
StarCraft 2
General
herO wins SC2 All-Star Invitational PhD study /w SC2 - help with a survey! Oliveira Would Have Returned If EWC Continued StarCraft 2 not at the Esports World Cup 2026 [Short Story] The Last GSL
Tourneys
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) OSC Season 13 World Championship $70 Prize Pool Ladder Legends Academy Weekly Open! SC2 All-Star Invitational: Jan 17-18 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 510 Safety Violation Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained
Brood War
General
Which foreign pros are considered the best? [ASL21] Potential Map Candidates Gypsy to Korea BGH Auto Balance -> http://bghmmr.eu/ Fantasy's Q&A video
Tourneys
[Megathread] Daily Proleagues Azhi's Colosseum - Season 2 Small VOD Thread 2.0 [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Current Meta Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Game Theory for Starcraft
Other Games
General Games
Beyond All Reason Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026!
Dota 2
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 Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Canadian Politics Mega-thread European Politico-economics QA Mega-thread NASA and the Private Sector
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
How Esports Advertising Shap…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1284 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
Wardi Open
14:00
#71
WardiTV3520
Rex104
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech127
Rex 104
Harstem 58
gerald23 3
StarCraft: Brood War
Rain 4090
Calm 3496
Jaedong 1367
Flash 1176
Larva 863
BeSt 725
Hyuk 589
Mini 550
Light 497
Soma 419
[ Show more ]
Stork 391
firebathero 321
ZerO 317
ggaemo 308
Snow 250
Soulkey 232
actioN 227
Barracks 119
Rush 111
JYJ 109
Sharp 100
Zeus 98
Mind 96
Pusan 84
Shuttle 73
JulyZerg 50
PianO 50
[sc1f]eonzerg 46
Mong 39
Shinee 34
Yoon 31
yabsab 28
sorry 28
ToSsGirL 27
Free 23
scan(afreeca) 21
Bale 20
Terrorterran 17
soO 17
HiyA 15
ivOry 15
ajuk12(nOOB) 13
GoRush 12
Rock 4
Dota 2
Gorgc4658
singsing2771
qojqva1225
Dendi491
420jenkins302
Fuzer 239
BananaSlamJamma138
Counter-Strike
kennyS2911
olofmeister2111
byalli733
Super Smash Bros
Mew2King105
Other Games
B2W.Neo1097
hiko552
Pyrionflax251
crisheroes233
Happy194
Hui .148
ToD133
edward27
ZerO(Twitch)24
Organizations
StarCraft: Brood War
UltimateBattle 1087
lovetv 9
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV327
• lizZardDota260
League of Legends
• TFBlade2042
Upcoming Events
Monday Night Weeklies
2h 46m
OSC
9h 46m
Replay Cast
18h 46m
RongYI Cup
20h 46m
Clem vs TriGGeR
Maru vs Creator
WardiTV Invitational
23h 46m
Replay Cast
1d 18h
RongYI Cup
1d 20h
herO vs Solar
WardiTV Invitational
1d 23h
The PondCast
2 days
HomeStory Cup
3 days
[ Show More ]
Korean StarCraft League
4 days
HomeStory Cup
4 days
Replay Cast
5 days
HomeStory Cup
5 days
Replay Cast
6 days
Liquipedia Results

Completed

BSL 21 Non-Korean Championship
OSC Championship Season 13
Underdog Cup #3

Ongoing

CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Acropolis #4 - TS4
Rongyi Cup S3
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025

Upcoming

Escore Tournament S1: W6
Escore Tournament S1: W7
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 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.