Пример #1
0
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()
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')
    file.write('')
    length = listobj.size()
    f = open('abc.txt', 'a+')
    # write word of linked list into the file
    for i in range(0, length):
        file.write(" " + listobj.index(i))
    file.close()
    print("\nthe word is deleted.....")

else:
    listobj.add(word)
    print("After searching element in the list ")
    # after adding the element Unordered list
    listobj.printList()
    # adding the word to file
    add_word = Node(word)
    listobj.add(add_word)