Code Monkey home page Code Monkey logo

bagadt's Introduction

bagADT

The-Bag-ADT Bag data structures The Bag ADT

Write an implementation for data structure Bag as a Java class, which is similar to a set, but it may contain several instances of the same member. For example, {'to', 'be', 'or', 'not', 'to', 'be'} is a bag of words, which is equal to {'be', 'be', 'not', 'or', 'to', 'to'} (since order of members is insignificant), but is unequal to {'be', 'not', 'or', 'to'} (since the number of instances is significant). Adding a member increases the number of instances in the bag by one and removing a member decreases the number of instances in the bag by one. The member is deleted from the bag when it has no instances.

Think that “how would you represent a bag without actually storing multiple instances of the same member?” Your implementation should be efficient.

Don’t forget that you cannot use any pre-written Java Api Class. You must write your own code for data structures (You are allowed to use lab source codes that we examined so far.)

Your implementation must be generic, i.e. your bag can accept any type of instances. (Use Java Generics !)

Your ADT should provide at least these operations:

 add(T item) : Inserts item in the bag.  clear() : Removes all of the elements from this bag.  contains(T item) : Returns true if this bag contains the specified element and false otherwise.  distictSize() : Returns the distinct number of elements in this bag. (For example, for the bag {'to', 'be', 'or', 'not', 'to', 'be'} distinctSize is 4)  elementSize(T item) : Returns the number of this item in this bag. (For example, for the bag {'to', 'be', 'or', 'not', 'to', 'be'} elementsize(‘be’) is 2)  isEmpty() : Returns true if this collection contains no elements.  remove(T item) : Removes a single instance of item from this bag and returns true if it is present; otherwise returns false.  size() : Returns the total number of elements in this bag. (For example, for the bag {'to', 'be', 'or', 'not', 'to', 'be'} size is 6)  toString() : Returns a string that displays the elements in the bag.

Please write a Test program (a separate Java class) proves that your container(bag) works properly.

bagadt's People

Contributors

firtanaelif avatar

Watchers

James Cloos avatar  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.