CS 245 - Programming Languages
Lab 10
Elixir -- your own linked list
Write, in Elixir, code to create and provide functionality for you own linked list implementation. You should write code to do the following:
- Define a structure to implement the node of a linked list (the structure should have a data payload and a pointer to the next node)
- Define a structure to hold a linked list. The contents of the structure should be a pointer to the head of the linked list and the number of nodes in the linked list.
- Create a method to add a new node at the front of a linked list. The method show take two arguments: a data item and a linked list struct. The returned value should be a linked list struct.
- Create a method to print the contents of one of your linked lists
- Create a method that adds a data item to the tail of a linked list. It should take a data item and a linked list struct as arguments. It should return a linked list struct.
- Create a function that appends one of your lists to another of your lists. The method should take two list structs as arguments and return a list struct.
For example, if your code is in a module named MyLL then you might have the following interaction.
a = MyLL.addHead("a", nil)
b = MyLL.addHead("b", a)
c = MyLL.addTail("c", b)
MyLL.printList(b)
b -> a
MyLL.printList(c)
b -> a -> c
MyList.appendLists(c, b)
b -> a -> c -> b -> a
What to hand in
Send all of your code to gtowell@brynmawr.edu