Monday, June 15, 2015

Bag Data Structure Implementation in Java


A Bag is a collection where removing items is not supported. It purpose is to provide users with the ability to collect items and then to iterate through the collected items. At the end you have an option to empty the complete bag.

In this implementation you have an additional method to increase the Bag storage.

You can get the eclipse project and the project jar from here.

You can simply run the jar file from the terminal as :- 

java -jar Bag.jar

It will simply show you the output the sample test file for the Bag DS. I will provide the source for the test file which shows how to use it. Here's the code :-


Output  :- 

Initial Size of Bag (No of elements): 0
Capacity (No. of items the bag can hold) :5
Size of Bag after inserting items : 4
Capacity of Bag after extending the size :10
Size of Bag after inserting more items : 8
Elements present in the Bag :- 

12
212
1
123
142
12
19
131
No. of elements in the Bag (When used counter) :8
Size of Bag after clearing : 0


I hope you liked this post. Share it in your social networks.

Thank you.

0 comments :

Post a Comment

Follow Me!

Blog Archive

Followers

Visitor Map