|
1 | 1 | # Instructions
|
2 | 2 |
|
3 |
| -Implement a doubly linked list. |
| 3 | +Your team has decided to use a doubly linked list to represent each train route in the schedule. |
| 4 | +Each station along the train's route will be represented by a node in the linked list. |
4 | 5 |
|
5 |
| -Like an array, a linked list is a simple linear data structure. Several |
6 |
| -common data types can be implemented using linked lists, like queues, |
7 |
| -stacks, and associative arrays. |
| 6 | +You don't need to worry about arrival and departure times at the stations. |
| 7 | +Each station will simply be represented by a number. |
8 | 8 |
|
9 |
| -A linked list is a collection of data elements called *nodes*. In a |
10 |
| -*singly linked list* each node holds a value and a link to the next node. |
11 |
| -In a *doubly linked list* each node also holds a link to the previous |
12 |
| -node. |
| 9 | +Routes can be extended, adding stations to the beginning or end of a route. |
| 10 | +They can also be shortened by removing stations from the beginning or the end of a route. |
13 | 11 |
|
14 |
| -You will write an implementation of a doubly linked list. Implement a |
15 |
| -Node to hold a value and pointers to the next and previous nodes. Then |
16 |
| -implement a List which holds references to the first and last node and |
17 |
| -offers an array-like interface for adding and removing items: |
| 12 | +Sometimes a station gets closed down, and in that case the station needs to be removed from the route, even if it is not at the beginning or end of the route. |
18 | 13 |
|
19 |
| -* `push` (*insert value at back*); |
20 |
| -* `pop` (*remove value at back*); |
21 |
| -* `shift` (*remove value at front*). |
22 |
| -* `unshift` (*insert value at front*); |
| 14 | +The size of a route is measured not by how far the train travels, but by how many stations it stops at. |
23 | 15 |
|
24 |
| -To keep your implementation simple, the tests will not cover error |
25 |
| -conditions. Specifically: `pop` or `shift` will never be called on an |
26 |
| -empty list. |
| 16 | +```exercism/note |
| 17 | +The linked list is a fundamental data structure in computer science, often used in the implementation of other data structures. |
| 18 | +As the name suggests, it is a list of nodes that are linked together. |
| 19 | +It is a list of "nodes", where each node links to its neighbor or neighbors. |
| 20 | +In a **singly linked list** each node links only to the node that follows it. |
| 21 | +In a **doubly linked list** each node links to both the node that comes before, as well as the node that comes after. |
27 | 22 |
|
28 |
| -If you want to know more about linked lists, check [Wikipedia](https://en.wikipedia.org/wiki/Linked_list). |
| 23 | +If you want to dig deeper into linked lists, check out [this article][intro-linked-list] that explains it using nice drawings. |
| 24 | +
|
| 25 | +[intro-linked-list]: https://medium.com/basecs/whats-a-linked-list-anyway-part-1-d8b7e6508b9d |
| 26 | +``` |
0 commit comments