Jump to content

Linked list of arrays Java help

Go to solution Solved by colonel_mortis,

As I understand it, your structure is

  • BedAndBreakfast class contains all the state for a particular B&B
  • Array class contains an array of BedAndBreakfast instances
  • Node class which contains an instance of Array as well as (a pointer to) the successor (and maybe predecessor too if it's a doubly linked list)
  • List class which has (a pointer to) the first Node

In your description, it sounds like you are just using the array as an implementation for a list, so there's no additional semantics aside from the order that the elements appear (aka if two things being in the same array or different arrays is irrelevant). If that is the case, I would suggest putting the add method in the List class, which means that you can change the internal implementation of the list without affecting any of the users. In general, the instances of Node and Array should not be accessible to users of the class - they should just modify your list via the interface provided by List.

 

Normally I would suggest implementing the List interface, but if it's an assignment then I presume the person who designed the course knows that they're doing, and you will cover all the relevant stuff.

Hey guys, I'm supposed to have an assignment that is a linked list of arrays (technically doubly linked list but close enough) So far I've made:

-a list class that has a node object of head

-a node class for that list to use which has a name in it.

-an array class which has an array of "bed and breakfast" objects in it

-a bnb class that has a name, description, rating, etc.

My question is if I'm trying to add a bed and breakfast into the array in a node, where would I put this function? This whole object oriented concept is pretty new to me so I am not sure where I should put this. I was thinking that I could put the function in the array class, but then I am not sure how I would check if it is the proper node to add the BNB to. Any tips are much appreciated.

 

EDIT: Oops posted this in OS somehow

i5 4670k| Asrock H81M-ITX| EVGA Nex 650g| WD Black 500Gb| H100 with SP120s| ASUS Matrix 7970 Platinum (just sold)| Patriot Venom 1600Mhz 8Gb| Bitfenix Prodigy. Build log in progress 

Build Log here: http://linustechtips.com/main/topic/119926-yin-yang-prodigy-update-2-26-14/

Link to comment
https://linustechtips.com/topic/753373-linked-list-of-arrays-java-help/
Share on other sites

Link to post
Share on other sites

As I understand it, your structure is

  • BedAndBreakfast class contains all the state for a particular B&B
  • Array class contains an array of BedAndBreakfast instances
  • Node class which contains an instance of Array as well as (a pointer to) the successor (and maybe predecessor too if it's a doubly linked list)
  • List class which has (a pointer to) the first Node

In your description, it sounds like you are just using the array as an implementation for a list, so there's no additional semantics aside from the order that the elements appear (aka if two things being in the same array or different arrays is irrelevant). If that is the case, I would suggest putting the add method in the List class, which means that you can change the internal implementation of the list without affecting any of the users. In general, the instances of Node and Array should not be accessible to users of the class - they should just modify your list via the interface provided by List.

 

Normally I would suggest implementing the List interface, but if it's an assignment then I presume the person who designed the course knows that they're doing, and you will cover all the relevant stuff.

HTTP/2 203

Link to post
Share on other sites

1 hour ago, colonel_mortis said:

As I understand it, your structure is

  • BedAndBreakfast class contains all the state for a particular B&B
  • Array class contains an array of BedAndBreakfast instances
  • Node class which contains an instance of Array as well as (a pointer to) the successor (and maybe predecessor too if it's a doubly linked list)
  • List class which has (a pointer to) the first Node

In your description, it sounds like you are just using the array as an implementation for a list, so there's no additional semantics aside from the order that the elements appear (aka if two things being in the same array or different arrays is irrelevant). If that is the case, I would suggest putting the add method in the List class, which means that you can change the internal implementation of the list without affecting any of the users. In general, the instances of Node and Array should not be accessible to users of the class - they should just modify your list via the interface provided by List.

 

Normally I would suggest implementing the List interface, but if it's an assignment then I presume the person who designed the course knows that they're doing, and you will cover all the relevant stuff.

That makes sense, thank you!

i5 4670k| Asrock H81M-ITX| EVGA Nex 650g| WD Black 500Gb| H100 with SP120s| ASUS Matrix 7970 Platinum (just sold)| Patriot Venom 1600Mhz 8Gb| Bitfenix Prodigy. Build log in progress 

Build Log here: http://linustechtips.com/main/topic/119926-yin-yang-prodigy-update-2-26-14/

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×