Hey, for an assignment i am meant to write a function called delete as part of my ListLinked ADT, this is easy enough and here is my code:

/**
     *deletes the element under w and places w over the next element
     *@param window w
     *@return the element under w
     *@exception OutOfBounds if w is in the before first or after last position
     */
    public Object delete(WindowLinked w) throws OutOfBounds {
        if (!isBeforeFirst(w)&&!isAfterLast(w)) { 
            Object element=w.link.item;
            Link current = before.successor; 
            Link previous = before; 
            while (current != w.link) {
                previous = current; 
                current = current.successor;
            } 
            previous.successor=w.link.successor;
            previous.successor=w.link;
            return element;
        } 
            else throw new OutOfBounds("deleting before start or after end.");
    }

but now we are meant to write the function so it has constant time perfromance, so i can't use the while loop in my function.
can anyone help about how to go about this.

I think im meant to create a new link before or after the windowlink but even if i do that i dont know how to get the previous link to point to the w.link.successor, any ideas??

thanks

use code tags so your code is more readable [*code*][*/code*]

without the stars

And could you tell a little more about the problem, i'm not sure if I get what youre trying to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.