Results 1 to 9 of 9
- 03-16-2011, 08:24 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
- 03-17-2011, 07:29 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 03-17-2011, 03: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:
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, 03:53 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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,
JosBuild a wall around Donald Trump; I'll pay for it.
- 03-17-2011, 03: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, 04:25 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 03-17-2011, 08: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, 09:20 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Build a wall around Donald Trump; I'll pay for it.
- 03-17-2011, 09: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.
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, 10:34 AM -
Linked List node class help!!
By SteroidalPsycho in forum New To JavaReplies: 0Last Post: 05-03-2010, 02: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, 10:16 AM -
Creating an Iterator for Linked List
By spanky in forum New To JavaReplies: 3Last Post: 10-05-2008, 08:16 PM -
creating a deck of cards using a linked list
By boomba88 in forum New To JavaReplies: 2Last Post: 09-11-2008, 04:34 PM
Bookmarks