5
1
Challenge
Write the shortest program that implements the minimum requirements for a linked list, stack and queue.
Minimum requirements
- Functions that allow the user to add and remove elements from the linked list, stack and queue.
- Any data type can be added to the linked list, stack and queue (string, int, etc.).
- One special function (e.g. sort letters alphabetically).
- The program must work (compile without errors and operations and results should make sense in the context of linked lists, stacks and queues)!
- Lastly, this program must be hard-coded. Arrays, however, are allowed (please refer to the restrictions section).
Winning criteria
- Standard Codegolf rules.
- Number of characters based on the summation of characters for linked list, stack and queue.
Restrictions
- No trivial answers (i.e. 0 or 1 for a stack based language).
- You are allowed to write the program in any language except for stack-based languages (let me know if this is unfair).
- You cannot simply use the functions of another class. If a language (like Ruby) already has
push
andpop
functions in arrays or any other class, you must write your ownpush
andpop
functions.
Little blurb: If this code golf challenge is too simple, I will add more requirements. I'm also open to any suggestions.
Mhh, not really clear. What prevents me from doing
class A extends java.util.Stack {}
? – Johannes Kuhn – 2013-11-08T22:13:53.097@JohannesKuhn Good point, updated. – Rob – 2013-11-08T22:24:42.620
2what if, for example, in Ruby arrays have
push
,pop
, andshift
, so technically arrays are stacks and queues. They behave like linked lists, because linked lists are basically just arrays, so the default array already pretty much meets these requirements... – Doorknob – 2013-11-08T22:34:24.717@Doorknob So "hard-coded functionality" would be better wording for this question? I guess restricting trivial answers is too generic... I'll think of a better way to word "trivial". – Rob – 2013-11-08T23:43:55.647
1I don't know how I could do this without using arrays... – Doorknob – 2013-11-08T23:49:23.297
@Doorknob You can. I want people to write their own
push
andpop
functions, not use the defaults already implemented in the language. – Rob – 2013-11-08T23:51:44.490So, we only need to write
push
,pop
, andshift
functions? I'll do it now – Doorknob – 2013-11-09T02:08:10.820@Doorknob Hmm, this question sounded a lot better in my head... Oh well. At least it will be good practice for beginners. – Rob – 2013-11-09T13:30:57.740
@Doorknob But in that case you just have a single Deque/List hybrid, not a separate list, stack, and queue (though the question doesn't seem to specify that they have to be separate) – SuperJedi224 – 2017-05-24T11:15:50.307