# CC2203-Les08LinkedList-for-viewing - 8-1/35Lesson 8: Linear...

This preview shows pages 1–14. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: 8-1/35Lesson 8: Linear Lists – Linked Structure•After completing this lesson, you should be able to do the following:–Use Pointer to represent Linear List–Implement Linear List Structure and Operations with Java pointer8-2/35Linear (or Ordered) Listsinstances are of the form(e, e1, e2, …, en-1)where eidenotes a list elementn >= 0 is finitelist size is n8-3/35Linear ListsL = (e, e1, e2, e3, …, en-1)relationshipseis the zero’th (or front) elementen-1is the last elementeiimmediately precedes ei+18-4/35Linear List ExamplesStudents in CC2203 =(Jack, Jill, Abe, Henry, Mary, …, Judy)Quizzes in CC2203 =(quiz1, quiz2, quiz3)Days of Week = (S, M, T, W, Th, F, Sa)Months = (Jan, Feb, Mar, Apr, …, Nov, Dec)8-5/35Linear List Operations—size()determine list sizeL = (a,b,c,d,e)size = 58-6/35Linear List Operations—get(theIndex)get element with given indexL = (a,b,c,d,e)get(0) = aget(2) = cget(4) = eget(-1) = errorget(9) = error8-7/35Linear List Operations—indexOf(theElement)determine the index of an elementL = (a,b,d,b,a)indexOf(d) = 2indexOf(a) = 0indexOf(z) = -18-8/35Linear List Operations—remove(theIndex)remove and return element with given indexL = (a,b,c,d,e,f,g)remove(2) returns cand Lbecomes (a,b,d,e,f,g)index ofd,e,f, andg decrease by18-9/35Linear List Operations—remove(theIndex)remove and return element with given indexL = (a,b,c,d,e,f,g)remove(-1) => errorremove(20) => error8-10/35Linear List Operations—remove(theElement)remove(h) => no element removedremove the first occurrence of the specified element.L = (a,b,c,d,e,f,g)remove(c) and Lbecomes (a,b,d,e,f,g)index ofd,e,f, andg decrease by18-11/35Linear List Operations—add(theIndex, theElement)add an element so that the new element has a specified indexL = (a,b,c,d,e,f,g)add(0,h) => L = (h,a,b,c,d,e,f,g)index ofa,b,c,d,e,f, andg increase by18-12/35Linear List Operations—add(theIndex, theElement)L = (a,b,c,d,e,f,g)add(2,h) => L = (a,b,h,c,d,e,f,g)index ofc,d,e,f, andg increase by1add(10,h) => erroradd(-6,h) => error8-13/35The Class Chain8-14/35...
View Full Document