Skip to content

Day 3 #6

Description

@githubdudu

Review of yesterday's

My possible solution is on this branch: https://github.com/githubdudu/react-study-group/tree/day2-solution

  1. This way of addLast is very inefficient because we have to iterator all the elements in the list.
    @Override
    public void addLast(Object item) {
        add(size, item);
    }

We shall directly use sentinel.prev to get the last element. By using sentinel, we implement the DLL as a circle.

    @Override
    public void addLast(V item) {
        // TODO: make this method as efficient as possible
        Node newNode = new Node(item, sentinel.prev, sentinel);
        sentinel.prev.next = newNode;
        sentinel.prev = newNode;
        size++;
    }
  1. We can utilize the generic to finish task 2. Object type is not a better way. :-)

    Image

  2. You may notice there is an error in JavaScript version. To fix this error, we must either rename the size() function or rename the this.size property.
    This is because in the class of JS, property and function are all treated as objects. An override will happen if there is a same-name declaration.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions