Section5-6Key 1 - Sofution // Class Linkedlntl.isl to...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sofution // Class Linkedlntl.isl to CSE143 Section used to store can be { #F Probl-ems (9 of integers. a list LinkedlntList :ublic class private front, ListNode constructs / / post: public Linkedlntlist nu11; front ) // first list value in the list an emPty O{ number of returns the current / / post: public int size O { j-nt count O; front; ListNode current !: nulf ) { whil-e (current r-rr r4nf r CUrrent . neXt i count ++; ) return counLi ) : 0 (: index < size o / / pre post: returns the integer at the // get (int publi.c index) int { ListNode current front; (int i++) for i- - 0; i < index; current. next; current return current . data; ) // nnet-. \Fv!, elements in the list "' given index in the list ^raates a Comma-separated, braCketed verSiOn Of the liSt public if String toSLring ( ) { (front nulI) return ""i efse { wIrr + front.data; String result: ListNode front.next; current whil-e (current l: nul-l) { +: " , rr + current. data; result current current. next; ) +: "]"; result ralrrrn !vveret raqrr"l i. ) ) / / ^ cf ' -oturns the position of the (-1 if value not found) // public int indexOf(int value) { index O; int front; ListNode current I(current while nu11) { :: valu€) (current.data if return index; index++; current current. next; ) -L; return Ir'vvg first occurrence of the given I ...
View Full Document

Ask a homework question - tutors are online