I'm learning to write a bag class and have written this code that adds elements into the existing bag. Problem is that once I return the bool type for the array, it doesn't print the array as I planned.
You add elements to bag b but print the elements of bag instance.
I also don't understand why a number is passed to the print function when it's not used for anything within the function.
On line 82 you add an element to an already full bag. The add function doesn't check if the bag is already full so it will just write outside the data array.
Okay, I fixed that error. It acknowledges that there are five and later six elements of the bag, but I think what I'm trying to ask is how do I display the value of the five/six elements of the bag?
Okay, so I fixed it and it does print the five elements. Is there any way I can remove elements from a bag? There are very few reference to bags on the site.
You can do as Zhuge says but as I understand it the order of the elements in a bag is not important. If that's so you could just copy the last element to the position that you want to remove and decrement the count variable.