class node:
def __init__(self, pdata):
self.data = pdata
self.pointer = None
class linkedlist:
def __init__(self):
self.head = None
def insertfront(self, pdata):
newnode = node(pdata)
if self.head is None:
self.head = newnode
return
else:
newnode.pointer = self.head
self.head = newnode
def insertindex(self, data, index):
newnode = node(data)
currentnode = self.head
pos = 0
if pos == index:
self.insertfront(data)
else:
while (currentnode != None and pos+1 != index):
pos+=1
currentnode = currentnode.pointer
if currentnode != None:
newnode.pointer = currentnode.pointer
currentnode.pointer = newnode
else:
print("index not present")
def insertEnd(self, data):
newnode = node(data)
if self.head is None:
self.insertfront(data)
return
else:
currentnode = self.head
while (currentnode.pointer):
currentnode = currentnode.pointer
currentnode.pointer = newnode
def Output(self):
currentnode = self.head
while (currentnode.pointer != None):
print(currentnode.data)
currentnode = currentnode.pointer
print(currentnode.data)
def Delfront(self):
if self.head == None:
return
else:
self.head = self.head.pointer
def Dellast(self):
if self.head == None:
return
elif self.head.pointer == None:
self.Delfront()
else:
currentnode = self.head
while currentnode.pointer.pointer != None:
currentnode = currentnode.pointer
currentnode.pointer = None
#def deleteatend(self):
print("af, means add to front of linked list\n"
"al, means add to last of linked list\n"
"ai, means add to index of linked list\n"
"df, means delete from front of linked list\n"
"dl, means delete from last of linked list\n"
"di, means delete from index of linked list\n"
"o, means output linked list\n")
x = ""
llist = linkedlist()
while x != "e":
x = input("What do you want to do to the linked list\n>>>")
if x == "af":
y = input("Enter the data")
llist.insertfront(y)
elif x == "al":
y = input("Enter the data")
llist.insertEnd(y)
elif x == "ai":
y = input("Enter the data")
index = int(input("Enter the index location"))
llist.insertindex(y, index - 1)
elif x == "df":
llist.Delfront()
elif x == "dl":
llist.Dellast()
elif x == "o":
print("Llist is starting>")
llist.Output()
print("<Thats all folks")
else:
print("please input something appropriate")
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}