Git Product home page Git Product logo

6b_merger's Introduction

hw6B Note

In UserOfMerge.java, the test will always give false.

This is because in the alphabet, "K" is before "Q". However, with cards, "Q" is before "K". Since Java follows the hierarchy of the alphabet, NOT cards, the test will always give false.

merge sorted lists

The lists are stored contiguously in a piece of an ArrayList, specified by the indexes at their boundaries.

For example, here is a picture of the two sorted lists of card values that we merged in class on Wednesday 2019-05-08, preceded by 2 positions whose values are to be ignored, and followed by 3 positions whose values are to be ignored. The values to be ignored are represented here by _.

values:  _ _ "4" "5" "6" "9" "2" "3" "4" "6" "7" "J" "Q" "K" _  _  _
indexes: 0 1  2   3   4   5   6   7   8   9   10  11  12  13 14 15 16 

The boundaries (check my counting!) are represented with half-open intervals:

  • list0 starts at index 2 with the String value "4"
  • list1 starts at index 6 with the String value "2". Since the lists are "stored contiguously", that 6 also marks the position just past the end of list0. The last value in list0 is therefore "9".
  • list1 ends just before index 14, with a last value of "K".

The resulting, merged list is to occupy the original range. In the example above that means the interval [2,14).

We need not merge in place. (Doing so is apparently complicated.) So start your merge procedure by allocating storage to hold a copy of the data. Copy the data, then merge from the copy into the range whence it arrived.

You are of course welcome to look into in-place merges. But get this merge working first.

6b_merger's People

Contributors

leiapark avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.