Creating a LinkedList class from scratch

后端 未结 11 739
慢半拍i
慢半拍i 2020-12-02 06:52

We were given an assignment to create a LinkedList from scratch, and there are absolutely no readings given to guide us on this migrane-causing task. Also everything online

11条回答
  •  执笔经年
    2020-12-02 07:23

    Hint 1: read the description of linked lists at http://en.wikipedia.org/wiki/Linked_list

    Hint 2: the Java implementation of LinkedList is a doubly linked list. Yours is a singly linked list. The algorithms don't directly apply.


    Also:

    ... but creating [a linked list class] from scratch makes no sense whatsoever.

    It depends on what the required outcome of the work is. If the goal is to produce code that meets certain functional / non-functional requirements, then you are right. If the real goal is for you to learn how to program / design APIs / implement non-trivial data structures, then the utility of the final product is almost entirely irrelevant.

    And thus magically we have a linked list

    What you actually have there is a open data type, that could be used to build a (sort of) list. But that is not what your teacher wants. And it certainly would not be considered to be a useful list abstraction. A useful abstraction would include:

    • methods to do the things that programmers don't want to have to repeat over and over again, and

    • an abstraction layer that stops programmers "breaking" the list; e.g. by accidentally creating a cycle, or accidentally stitching a sublist in two lists to create an inverted tree.

提交回复
热议问题