class Stack: #Creating empty linked list to store stack __llist = None def __init__(self): self.__llist = Linkedlist() def Push(self, data): self.__llist.add(data) return def Pop(self): return self.__llist.delete(self.__llist.size()) def Peek(self): return self.__llist.delete(self.__llist.size(), False) def print(self): self.__llist.print_linked_list()
class Queue: #Creating empty linked list to store stack __llist = None def __init__(self): self.__llist = Linkedlist() def Add(self, data): self.__llist.add(data) return def Remove(self): return self.__llist.delete(1) def Peek(self): return self.__llist.delete(1, False) def print(self): self.__llist.print_linked_list()
for i in file: linkNode = Node(int(i)) listobj.sortlinklist(linkNode) listobj.printList() # take user input for search number = int(input("enter the number for search :")) # call the function search result = listobj.search(number) print(result) if result: listobj.delete_word(number) print("After Searching element in the list ") #after removing the element listobj.printList() #Delete the word form the file by over writting. file = open('number.txt', 'w') file.write('') file.close() print("\nthe word is deleted.....") else: listobj.add(number) print("After searching element in the list ") # after adding the element Unordered list listobj.printList() # adding the word to file add_word = Node(number) listobj.add(add_word) # open the file in append mode file = open('number.txt', 'a+') file.write(" " + str(number)) file.close()
""" # Program for UnOrdered List # Creating Object for Linked List from LinkedList import Linkedlist from LinkedList import Node obj = Node() listobj = Linkedlist() # Open and read the file openfile = open('abc.txt', 'r') # split the word of file file = openfile.read().split(" ") openfile.close() # itretive functoin for add into the linkedlist for i in file: listobj.add(i) # print the linked list listobj.printList() # use input word = str(input("\nenter the word for check:")) # call the function search result = listobj.search(word) print(result) if result: listobj.delete_word(word) print("After Searching element in the list ") #after removing the element listobj.printList() #Delete the word form the file by over writting. file = open('abc.txt', 'w')