Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Linked list qns  RSS feed

 
Timothy Leong
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
I have a customerDB class which contains an array of customer records.
I need to convert the array of customer records using linked list.

Should I
1) Declare a LinkedList class with insert,delete function and Node Class and make them as superclass of customerDB and customer records respectively?

or

2) Admend the customerDB class to include the head of the customer records, insert,delete function etc?

Which method do you think is more appropriate? Thank you very much
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is for a class where the point is to implement a LinkedList, I would go with the first option -- except I wouldn't make them super classes. A customerDB is not a Linked List -- it might have a linked list, but it is not one. Likewise, the customer records are not list nodes -- they might belong to a list node, but they are not nodes.

That said, I would write the Linked List class(es) and include it as a private member variable in the CustomerDB class. Then, I would write accessor methods that would take CustomerRecords objects and insert them into the list. This, you would call insert() on the customerDB object and it would turn around and call insert() on it's linked list.





If this is for a real-world application, I would simply use a java.util.LinkedList. (Of course, I would just call it a java.util.List, in case I ever needed to change it to a java.util.ArrayList later on.)
[ September 20, 2005: Message edited by: Joel McNary ]
 
Timothy Leong
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
thanks for the reply. I am kind of confuse now.

since I have a BankDatabase with an array of customer records, so

1) should I redefine my BankDatabase as BankDatabaseList from


2) I shall also redefine my Customer class as CustomerNode, correct??

I still have another qns
Every customer has their set of transaction records which is needed to be in linked list. This transaction holds the record of amount withdraw and deposit.

3) May I know where shall i place this transaction records into?? I think it's in CustomerNode but if it is in CustomerNode



Where should I put the insert transaction record coding into? I think I should need to have a transaction list too.

4) Since we have 2 linkedlist (BankDatabaselist and transactionList), 2 Nodes( customers and transaction), how should i declare a generic linkedlist class and node class to be used by all of them??


Thanks a lot. Your help is greatly appreciated.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!