예제 #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()
예제 #2
0
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()
예제 #3
0
 def __init__(self):
     self.__llist = Linkedlist()
예제 #4
0
"""
Read .a List of Numbers from a file and arrange it ascending Order in a
Linked List. Take user input for a number, if found then pop the number out of the
list else insert the number in appropriate position
"""
# 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('number.txt', 'r')
# split the word of file
file = openfile.read().split(" ")
openfile.close()
# itretive functoin for add into the linkedlist
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
 def __init__(self, l):
     queue = Linkedlist(l)
     self.head = queue.head
     self.tail = queue.tail
 def __init__(self, l):
     stack = Linkedlist(l)
     self.l = l
     self.head = stack.head
     self.tail = stack.tail
"""
-------------------------------------UnOrdered_List---------------------------------------------
Read the Text from a file,split it into words and arrange it as LinkedList.
Take  a user input to search a Word in the List. if the Word  is not found  then add it to the List,
and if it found  then remove the word  from the list . In the end save the List into a file
"""
# 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)