{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

notes44 - Implementing Ranked Sequences using Double Linked...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1/29/07 Implementing Ranked Sequences using Double Linked Lists DLLNode.java: class DLLNode { public: DLLNode _previous; DLLNode _next; Object _value; } DLLRankedSequence.java class DLLRankedSequence { int _n; //number of elements DLLNode _header; DLLNode _tail; public DLLRankedSequence() { _header = new DLLNode(); _tail = new DLLNode(); _header._next = _tail; _header._previous = _header; _tail._next = _header; _tail._previous = _header; _header._value = null; _tail._value = null; _n = 0; } DLLNode nodeAtRank (int max) throws OutofBoundsException { if ((index < 0) || index >= _N) throw new OutofBoundsException int i = 0; DLLNode node = _header._next; while (i<index) { node = node._next; i++; } return node; } void insertElementAtRank(int index, Object value) throws OutofBoundsException { DLLNode node; if (index >= 0 && index <= n) {
Image of page 1

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

View Full Document Right Arrow Icon
//between limits node = nodeAtRank(index); } else if (index == n) { //Insert at the end of list node = tail; } else {// out of range throw new OutofBoundsException(); } DLLNode newNode = new DLLNode(); newNode._value = value; //insert before "node" newNode._previous = node._previous; newNode._next = node; node._previous._next = newNode; node._previous = newNode;
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern