- 论坛徽章:
- 0
|
我现有一link list class,每个结点里含一个数,现在我想每个记录里包含两个实数,怎么修改?
- class ListNode
- {
- // package access members; List can access these directly
- Object data;
- ListNode nextNode;
-
- // constructor creates a ListNode that refers to object
- ListNode( Object object )
- {
- this( object, null );
- } // end ListNode one-argument constructor
-
- // constructor creates ListNode that refers to
- // Object and to next ListNode
- ListNode( Object object, ListNode node )
- {
- data = object;
- nextNode = node;
- } // end ListNode two-argument constructor
-
- // return reference to data in node
- Object getObject()
- {
- return data; // return Object in this node
- } // end method getObject
-
- // return reference to next node in list
- ListNode getNext()
- {
- return nextNode; // get next node
- } // end method getNext
- } // end class ListNode
-
- // class List definition
- public class List
- {
- private ListNode firstNode;
- private ListNode lastNode;
- private String name; // string like "list" used in printing
-
- // constructor creates empty List with "list" as the name
- public List()
- {
- this( "list" );
- } // end List no-argument constructor
-
- // constructor creates an empty List with a name
- public List( String listName )
- {
- name = listName;
- firstNode = lastNode = null;
- } // end List one-argument constructor
-
- // insert Object at front of List
- public void insertAtFront( Object insertItem )
- {
- if ( isEmpty() ) // firstNode and lastNode refer to same object
- firstNode = lastNode = new ListNode( insertItem );
- else // firstNode refers to new node
- firstNode = new ListNode( insertItem, firstNode );
- } // end method insertAtFront
- ...
-
- public static void main( String args[])
- {
- List list1 = new List();
-
- int array1[] = { 160, 591, 114, 229, 230, 270, 128, 1657, 624, 1503 };
- //insert numbers in list
- for (int c1 = 0; c1 < array1.length; c1++ )
- list1.insertAtFront(array1[ c1 ]);
- }
- ...
复制代码 |
|