Results 1 to 9 of 9
- 03-16-2011, 07:24 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
- 03-17-2011, 06:29 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 03-17-2011, 02:16 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Hmm, this make sense. I'm doing this for an assignment, and part of the reqs are to make an inner Term class with 2 int fields and another 2 int fields in a constructor. This is paired with an inner Node class that also has two fields (Node and Term), along with a constructor that also has Node and Term params.
I suppose I could do this:
But what else should I add?Java Code:public class Term { int c, x; Node ply; public Term (int cf, int ex){ c=cf; x=ex; } } public class Node { Term aTerm; Node aNode; public Node(Term t1, Node n1){ aTerm=t1; aNode=n1; } }
- 03-17-2011, 02:53 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
I wouldn't do it that way: I'd use a TreeSet<Node> where a Node implements the Comparable<Node> interface which sorts on the exponent of the Node. That way the Nodes are automatically sorted and there can be only one Node with a certain exponent (just what you need).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-17-2011, 02:57 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
I think I understand what you're trying to do, but my prof wants me to do it with the node and term. Thanks for the suggestion though!
- 03-17-2011, 03:25 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-17-2011, 07:39 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Yes, we have to a Node field that represents the polynomial as a singly-linked list with a list head. We tend to do things the hard way.
- 03-17-2011, 08:20 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-17-2011, 08:27 PM #9
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Yes, I know, I'm writing them inside of another class, I just didn't want to clutter up the page here.
The biggest problem I'm having is how to represent the polynomial as a Node w/ a list head (and on top of this, ordered by exponent small to large).:confused: I haven't had experience with this yet, so any help would be appreciated!Java Code:class Example { class Term {...} class Node {...} }
Similar Threads
-
How to access an element of a linked list inside another linked list?
By smtwtfs in forum New To JavaReplies: 4Last Post: 02-21-2011, 09:34 AM -
Linked List node class help!!
By SteroidalPsycho in forum New To JavaReplies: 0Last Post: 05-03-2010, 01:21 AM -
How to link a Array elemant to a Linked list Node
By ravinda in forum New To JavaReplies: 2Last Post: 04-18-2009, 09:16 AM -
Creating an Iterator for Linked List
By spanky in forum New To JavaReplies: 3Last Post: 10-05-2008, 07:16 PM -
creating a deck of cards using a linked list
By boomba88 in forum New To JavaReplies: 2Last Post: 09-11-2008, 03:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks