try to get the current cursor position without removing the node

class List(object):
    ___slot___=('cursor', 'size')
    
    def __init__(self):
        self.cursor=EmptyCircleNode()
        self.size=0
    def __str__(self):
        result = "<"
        node = self.cursor
        count = self.size
        while count != 0:
            result = result + str(node.data)
            if count != 1:
                result = result + ", "
            node = node.next
            count -= 1
        result = result + ">"
        return result
class EmptyCircleNode(object):
    ___slot___=()

class CircleNode(object):
    ___slots___=('data', 'next')
    def __init__(self, datavalue,nextnode):
        self.data=datavalue
        self.next=nextnode
        
def add(element,circle):
    newNode = CircleNode(element, EmptyCircleNode())
    circle.size +=1
   
    if isinstance(circle.cursor,EmptyCircleNode):
        circle.cursor=newNode
    elif isinstance(circle.cursor, CircleNode):
        cur=circle.cursor
        while not isinstance(cur.next,EmptyCircleNode):
            cur = cur.next
        cur.next = newNode

    else:
        raise TypeError("Bad list node")
def remove(circle):
    circle.size -= 1
    
    if circle.size <= 0:               
        circle.next= circle.cursor.next
    else:                      
        prev = circle.cursor
        for i in range(circle.size-1):
            prev = prev.next
        prev.next = prev.next.next
        

def getCurrentElement(circle):
    cur = circle.cursor
    return cur
#this doesn't work....

What is the problem that you are having? You say on line 57, "this doesn't work". What bit doesn't work? What is exactly the problem? What is it meant to do?

You are not calling that function, how do you know it does not work? Looks like you have linked low level data structure. Can you tell if all code is yours and if not what you have added and how have you tested it?

This article has been dead for over six months. Start a new discussion instead.