• Post Reply Bookmark Topic Watch Topic
  • New Topic

Implementing a bag with a linked list  RSS feed

 
Justin Delaney
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My assignment is to implement a bag of integers using a singly-linked list and a class definition IntBag.

This is the code I have for my linked list but, where do I start to implement the "bag"? I'm totally lost on where to start.

 
Norm Radder
Ranch Foreman
Posts: 2240
28
 
Paul Clapham
Sheriff
Posts: 22526
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd start by declaring a Bag class with suitable methods for a Bag structure. Actually... now that I reread your instructions I see you're supposed to call your class IntBag. So start with that.

Your instructions also say your class is supposed to use a singly-linked list, so your IntBag class -- or rather, an instance of that class -- should create an instance of your linked list class and use that.

Actually now that I come to think of it, you haven't even got a linked list class yet. You should start with that, or at least start by creating such a class and making stubs for its methods.
 
Paul Clapham
Sheriff
Posts: 22526
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way it looks like you've got some preliminary answers on the cross-post. It would be polite for you to summarize those answers over here (and summarize our answers over there) so that people don't have to spend time thinking up answers which have already been given elsewhere.
 
Junilu Lacar
Sheriff
Posts: 11169
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your response in the other site about what is a bag isn't consistent with most definitions: http://algs4.cs.princeton.edu/13stacks/

Clearly define what a Bag is first so you know what capabilities you need to code and which ones you can leave out.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!