Closed dgraciac closed 3 years ago
@dgraciac Here is the interface proposal for this data structure. Let me know if you require any changes.
package main
class SinglyLinkedList<E> {
// Insert element at the beginning of the list
fun insertAtBeginning(element: E){
TODO()
}
// Insert element after a specified node
fun insertAfter(previousNode: E, element: E){
TODO()
}
// Insert element at the end of the list
fun insertAtEnd(element: E){
TODO()
}
// Delete a node of a specified position
fun deleteNode(position: E){
TODO()
}
}
Positions are integers
fun deleteNode(position: Int){
TODO()
}
Passing a node is not needed:
// Insert element after the first ocurrence of specified element
fun insertAfter(element: E){
TODO()
}
After this interface changes, you can go with the implementation.
Consider add this operations in this PR. But up to you.
fun get(index: Int): E
fun isEmpty(): Boolean
fun head(): E
Is this alright @dgraciac?
package main
class SinglyLinkedList<E> {
// Insert element at the beginning of the list
fun insertAtBeginning(element:E) {
TODO()
}
// Insert element at the end of the list
fun insertAtEnd(element:E) {
TODO()
}
// Delete a node of a specified position
fun deleteNode(position:Integer) {
TODO()
}
// Get element at a specified position
fun get(index:Integer):E {
TODO()
}
// Check is list is empty
fun isEmpty(): Boolean{
TODO()
}
// Find the element at the head of the list
fun head():E{
TODO()
}
}
Please remove this operation because I am not sure it is worth it:
// Insert element after a specified node
fun insertAfter(element:E) {
TODO()
}
You can start with the implementation.
First step
Search, read and understand information about lists, linked lists and singly linked lists, and how they are implemented.
Second step
You have to share a code snippet in markdown with an interface proposal for this data structure. Below you can find an interface example of an hypothetical data structure:
Third step
After @code-sherpas/kollections-maintainers approve your interface proposal, open a pull request with the data structure implementation and wait for comments.
Minimum acceptance criteria
Related resources: