Skip to content

Commit 7cf06b4

Browse files
committed
Merge pull request #188 from cebial/master
Rewrite of the linked-list problem.
2 parents 64d21f1 + 552006a commit 7cf06b4

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

linked-list.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
Deques have four fundamental operations (using Array terminology):
1+
Like an array, a linked list is a simple linear data structure. Several
2+
common data types can be implemented using linked lists, like queues,
3+
stacks, and associative arrays.
24

3-
* push (insert value at back)
4-
* unshift (insert value at front)
5-
* pop (remove value at back)
6-
* shift (remove value at front)
5+
A linked list is a collection of data elements called *nodes*. In a
6+
*singly linked list* each node holds a value and a link to the next node.
7+
In a *doubly linked list* each node also holds a link to the previous
8+
node.
79

8-
The difference between deque and Array performance is that a deque
9-
implements all of these operations in constant time. Even clever
10-
implementations of Array will often have to copy the entire Array in
11-
order to unshift.
10+
You will write an implementation of a doubly linked list. Implement a
11+
Node to hold a value and pointers to the next and previous nodes. Then
12+
implement a List which holds references to the first and last node and
13+
offers an array-like interface for adding and removing items:
1214

13-
Under the hood we'll use an Element class with two fields, `next` and
14-
`prev`, that are both writable.
15+
* `push` (*insert value at back*);
16+
* `pop` (*remove value at back*);
17+
* `shift` (*remove value at front*).
18+
* `unshift` (*insert value at front*);
1519

16-
To make the API usable, you'll use a Deque class as a proxy for this
17-
list. There two good ways to implement Deque: maintain separate
18-
references to the first and last Element, or maintain a reference to one
19-
of them and ensure that the list is circular.
20+
To keep your implementation simple, the tests will not cover error
21+
conditions. Specifically: `pop` or `shift` will never be called on an
22+
empty list.
2023

21-
To keep your implementation simple, the tests will not cover error
22-
conditions. Specifically: pop or shift will never be called on an empty
23-
Deque.
24+
If you want to know more about linked lists, check [Wikipedia](https://en.wikipedia.org/wiki/Linked_list).
25+
26+
---
2427

2528
In languages that do not have good support for mutability (such as
26-
Elixir or Erlang), you may choose to implement a functional Deque where
29+
Elixir or Erlang), you may choose to implement a functional list where
2730
shift and pop have amortized O(1) time. The simplest data structure for
2831
this will have a pair of linked lists for the front and back, where
2932
iteration order is front ++ reverse back.
33+
34+

linked-list.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
---
2-
blurb: "Write a Singly-Linked List implementation that uses the Proxy pattern"
3-
source: "Inspired by 'Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby', singly linked-lists."
4-
source_url: "http://www.brpreiss.com/books/opus8/html/page96.html#SECTION004300000000000000000"
2+
blurb: "Implement a doubly linked list"
3+
source: "Classic computer science topic"

0 commit comments

Comments
 (0)