public class PolyNode { // Constructors PolyNode( double coef, int exp ) { this( coef, exp, null ) } PolyNode( double coef, int exp, PolyNode n) { coefficient = coef; exponent = exp; next = n; } // data fields double coefficient; int exponent; PolyNode next; }Assume you also have an iterator that is defined as follows:
public class PolyListItr { // Constructor PolyListItr( PolyNode theNode) { current = theNode; } PolyNode current; // current position }Write a Java method int polyCompare(PolyListItr p1, PolyListItr p2) that takes a
PolyListItr p1
referencing polynomial1
and a
PolyListItr p2
referencing polynomial2, and returns 1 if
polynomial1 is >
polynomial2, 0 if they are equal, and -1 if polynomial1 is < polynomial 2.
Assume the PolyNode
s are ordered by decreasing exponent. Note,
you may add methods (i.e. write them yourself) to the
PolyListItr
class for use in polyCompare
,
but you may not assume you have any available to you.
StackLi
methods
below in your method, and don't worry about how the data type
StackLi
is implemented.
int topAndPop() void push(int x) boolean isEmpty()
LinkedListItr
L and return a LinkedListItr
pointing
to a new linked list
that contains the even numbered elements of the list (2nd, 4th, 6th elements,
etc.). Assume each ListNode has an integer data field data
and a ListNode
reference field next pointing to
the next node. Your method should leave the list L intact.
Assume ListNode
is defined as follows:
public class ListNode { // Constructors ListNode( int x ) { this( x, null ) } ListNode( int x, ListNode n) { data = x; next = n; } // data fields int data; ListNode next; }Assume you also have an iterator that is defined as follows:
public class LinkedListItr { // Constructor LinkedListItr( ListNode theNode) { current = theNode; } ListNode current; // current position }Note, you may add methods (i.e. write them yourself) to the
LinkedListItr
class for use in evenList
,
but you may not assume you have any available to you.
LinkedListItr
p that
references a
node to be deleted, write a Java method void delete(LinkedListItr p)
that deletes the node
from the list. Don't worry about any boundary conditions (i.e. empty list,
single element list, etc.). Assume you also have an iterator that is defined
as follows:
public class LinkedListItr { // Constructor LinkedListItr( ListNode theNode ) { current = theNode; } ListNode current; // current position }Note, you may add methods (i.e. write them yourself) to the
LinkedListItr
class for use in delete
,
but you may not assume you have any available to you.
LinkedListItr
referencing the tail node and will
return a LinkedListItr
referencing the new tail node after the
list is reversed (the head node becomes the new tail node). Assume a standard
ListNode class for a node with a data field and a
next pointer. You may also
assume have an iterator that is defined as follows:
public class LinkedListItr { // Constructor LinkedListItr( ListNode theNode ) { current = theNode; } ListNode current; // current position }Note, you may add methods (i.e. write them yourself) to the
LinkedListItr
class for use in reverse
,
but you may not assume you have any available to you.
/ (division operator) / \ / \ - * / \ / \ / \ 2 a ^ * / \ / \ b 2 * c / \ 4 a
class BinaryNode { Object element; // The data in the node BinaryNode left; // Left child BinaryNode right; // Right child }
class AvlNode { // Constructors AvlNode( Comparable theElement ) { this( theElement, null, null ) } AvlNode( Comparable theElement, AvlNode lt, AvlNode rt ) { element = theElement; left = lt; right = rt; height = 0; } // data fields Comparable element; // The data in the node AvlNode left; // Left child AvlNode right; // Right child int height; // Height }Assume you may also use the following method to compute the height of an AVL node:
// returns the height of node t, or -1, if null private static int height( AvlNode t ) { return t == null ? -1 : t.height; }