Questions tagged [bag]

An unordered collection that can contain duplicates

Contrast with the Set data structure.

Typically, a bag can count the number of a particular item that it contains. For example, 5 apples, 2 oranges, 1 banana.

164 questions
0
votes
5 answers

Building a bag class in Java

I'm in dire need of help with this project. I'm trying to implement a Bag class for a programming assignment, and I'm getting hung up on the addAll(), Union(), and equals(), methods. Edit: According to the assignment, addAll() is supposed to add all…
0
votes
3 answers

finding kth largest element in an array implemented bag

We have a collection of Comparables held in a bag and have to find the kth largest element. I copied the collection to a HashSet to remove duplicates, then converted the HashSet to an array to be sorted and consequently the kth element accessed.…
learner01
  • 21
  • 1
  • 4
0
votes
1 answer

Does a multiset or bag offer better time complexity than a simple hash that keeps the counts of keys?

Java has multiset, and SmallTalk has a Bag class, and they are said to be the same function: keep a set of values but allow multiple values (with a count for each). But seems like multiset can be implemented by a hash table that keeps counts on the…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
0
votes
2 answers

Hibernate: Bag - performance impact in the case of update or delete operations?

From "Apress - Beginning Hibernate From Novice to Professional" p. 161, where they explain the bag collection: If the elements lack a proper key, there will be a performance impact that will manifest itself when update or delete operations are …
rapt
  • 11,810
  • 35
  • 103
  • 145
0
votes
2 answers

What's the best way to order collections in Hibernate?

I have a list of sub-values for a class in Hibernate. My initial implementation was a Set, but that returns the values in what is essentially 'database order' (likely based on a clustered index, which is almost insertion order). I looked at…
Paul W Homer
  • 2,728
  • 1
  • 19
  • 25
-1
votes
1 answer

failed can't find input bag file in rs_bag2image code

I am trying to run "rs_bag2image" code (https://github.com/UnaNancyOwen/rs_bag2image) for extracting frames from a bag file. I am new in c++ and got the error "failed can't find input bag file" when I am running the code. It seems the issue occurs…
Ehsan
  • 1
  • 1
-1
votes
1 answer

How to write an implementation class for a Bag (or Multiset) ADT?

I have an assignment in which I need to write an implementation class for a Bag (or Multiset) ADT. Problem is, the assignment is worded in a way that's hard to follow and I'm not sure what exactly I need to do. Here is the assignment description and…
-1
votes
1 answer

How to check that the object isn't the last and how to handle it if it is?

I have a method that cycles through a Bag of geometry objects and gets specific attributes and compares the current attribute to the previous, if there is one, with the intention of storing the highest attribute and then assigning it to another…
KJGarbutt
  • 161
  • 8
-1
votes
1 answer

I'm trying to type a remove method that takes removes a random class from an array

I'm trying to get my program to work so that whenever a class is chosen, it removes it, it can be random or in order (I'm just trying to get it to work at this point). However when I run my current program, it just constantly loops without removing…
-1
votes
1 answer

Basic bag on the return value of a function on matlab

Consider the matlab function that describe in the image. enter image description here As I run this function, I get that y = 1 insted of y = 7 as expected. Why is this happening? any response will be appreciated. Thanks!
MrSonic
  • 363
  • 3
  • 10
-2
votes
1 answer

How to make a Black Jack game out of a predefinded deck class

So in class we had to do the ArrayBag class, which im sure all of you know about. If not its all over the internet. Anyway our project is to turn that into a black Jack game. I however have no idea how to do this. I would want to make a card class a…
-2
votes
1 answer

How to remove an item from linked list

I have a Bag class was given to me like looks like this: import java.util.Iterator; import java.util.NoSuchElementException; public class Bag implements Iterable { private int N; // number of elements in bag private…
user3268401
  • 319
  • 1
  • 7
  • 21
-2
votes
2 answers

What is meant by the term "bag"?

What is a "bag" in Java? I tried to find out from Google but I could not find a precise answer. I got idea from what I found on google that bags are similar to multisets. I want to know whether I am right or wrong because I didnt get proper answer…
Alok
  • 7,734
  • 8
  • 55
  • 100
-5
votes
3 answers

The method size() is undefined for the type test

Hello Im Getting an error on this line "int N = numbers.size();" says The method size() is undefined for the type Test
Firefox
  • 11
  • 5
1 2 3
10
11