• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 14:44
CET 20:44
KST 04: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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly) RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread ZeroSpace Megathread The Perfect Game Path of Exile
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
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
I decided to write a webnov…
DjKniteX
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1326 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
OSC
16:00
OSC Elite Rising Star #17
Shameless vs PercivalLIVE!
SteadfastSC237
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 588
SteadfastSC 237
ProTech130
IndyStarCraft 63
Railgan 12
StarCraft: Brood War
Britney 15193
Calm 2556
Shuttle 671
Larva 415
BeSt 236
firebathero 162
Dewaltoss 145
HiyA 13
NaDa 9
Dota 2
Gorgc6156
Dendi1098
420jenkins341
Counter-Strike
fl0m5585
chrisJcsgo65
kRYSTAL_16
Heroes of the Storm
Liquid`Hasu225
Khaldor156
Other Games
Grubby2097
Beastyqt577
Sick153
KnowMe109
ArmadaUGS98
C9.Mang093
RotterdaM84
Mew2King61
QueenE59
Trikslyr56
Livibee51
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• StrangeGG 50
• Reevou 11
• Dystopia_ 1
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• Kozan
• IndyKCrew
StarCraft: Brood War
• FirePhoenix10
• 80smullet 6
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV611
• lizZardDota256
League of Legends
• TFBlade629
Counter-Strike
• Shiphtur210
Other Games
• imaqtpie740
Upcoming Events
Replay Cast
4h 16m
Korean StarCraft League
1d 7h
CranKy Ducklings
1d 14h
WardiTV 2025
1d 16h
SC Evo League
1d 16h
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
2 days
WardiTV 2025
2 days
OSC
2 days
[ Show More ]
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
3 days
Wardi Open
3 days
StarCraft2.fi
3 days
Monday Night Weeklies
3 days
Replay Cast
4 days
WardiTV 2025
4 days
StarCraft2.fi
4 days
PiGosaur Monday
5 days
StarCraft2.fi
5 days
Tenacious Turtle Tussle
6 days
The PondCast
6 days
WardiTV 2025
6 days
StarCraft2.fi
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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 © 2025 TLnet. All Rights Reserved.