Exemple #1
0
def Calender_Using_Linked_List():  # function is created
    while True:
        try:
            llist = LinkedList()  # object is created for imported classes
            q = Queue1()
            month = int(input("which month's calender u wish to see in MM format :"))
            if month <= 0 or month >= 13:
                print("enter between 0 and 13")
                continue

            year = int(input("for which year YYYY format"))
            if year <= 1000 or year >= 3000:
                print("enter between 1000 and 3000")
                continue

            array = Calender(month, year)
            # try is used for locating the error
            for items in array:  # for loop is used using adding data in linked list
                for data in items:
                    q.AddRear(llist.Add(data))  # data is added in the linked list via queue class

            llist.PrintCalendar()  # now calendar is printed in linked list
            break

        except ValueError:  # exception will find the error
            print("please check the input ")
Exemple #2
0
def UnorderedlList():  # new function for linked list

    items = ReadFile("numbers")
    llist = LinkedList()
    try:  # try exception is used for the finding the error
        for data in items:  # data is added and printed in linked list format
            llist.Add(data)
    except AttributeError:  # error is caught if any
        print("please check the error ")
    llist.Print()
Exemple #3
0
def OrderedList():  # new function for

    items = ReadFile("numbers_1")
    llist1 = LinkedList()
    try:  # try exception is used if any error occurs

        for data in items:  # data is added and printed in linked list format
            llist1.Add(data)
        llist1.sortlist()

    except AttributeError:
        print("check the class attribute ")
Exemple #4
0
def Anagram_Queue():  # function created

    llist = LinkedList()  # object is created
    q = Queue1()
    anagram = PrimeAnagram()
    try:  # try catch is used to catch error if error
        for data in anagram:
            q.AddRear(
                llist.Add(data)
            )  # add rear function is used and data is added via linked list
        llist.Print()
        # q.PrintList()       # if we print queue we will data in none as linked list data type is None
    except AttributeError:
        print("check the class file for error")
Exemple #5
0
def Anagram_Reversed():  # function created

    llist = LinkedList()  # object is created
    stack = Stack()
    anagrams = PrimeAnagram()

    try:  # try exception is used for the finding the error
        for data in anagrams[::-1]:
            stack.Push(
                llist.Add(data)
            )  # push function is used and data is pushed via linked list
        llist.Print()
        # print(stack.size())  # if we print stack we will data in none as linked list data type is None

    except AttributeError:  # if error found exception is print the below statement
        print("please check class file  ")
Exemple #6
0
class Stack:
    """
    stack class is created with different attribution
    """
    def __init__(self):
        self.items = []
        self.ul = LinkedList()

    def IsEmpty(self):  # is_empty is used for the return list true if empty
        return self.items == []

    def Push(
            self,
            items):  # push function is created to append the data in the stack
        self.items.append(items)
        self.ul.Add(items)

    def Pop(self
            ):  # pop function is used for the removing a data from last index
        return self.items.pop()

    def Peek(self):  # peek is used to check the first data on the stack
        if not self.IsEmpty():
            return self.items[0:1]

    def Size(self):  # size function will give out the size of the stack
        return self.items
Exemple #7
0
class Queue1:
    """
    queue called is created with different attribution
    """
    def __init__(
        self
    ):  # queue is used for linked list as linked list is called in queue
        self.ul = LinkedList()
        self.items = []

    def Dequeue(self):  # de-queue is used for popping data from queue
        self.items.pop()

    def AddRear(
            self,
            data):  # add gear is used for adding data at the end for the array
        self.items.insert(0, data)
        return self.ul.Add(data)

    def AddFront(
            self,
            data):  # add front is used for adding adding in front of the queue
        self.items.append(data)
        return self.ul.Add(data)

    def RemoveRear(self):  # remove function is used removing data from rear
        return self.items.pop(0)

    def RemoveFront(
            self
    ):  # remove front is used or removing data from front of the array
        return self.items.pop()

    def IsEmpty(self):  # is empty is used for empty the function
        return self.items == []

    def Size(
            self):  # size function is used for checking the length of the data
        print(len(self.items))

    def PrintList(self):  # print list is used for printing function
        # print(self.items)
        self.ul.Print()

    def QueueList(
            self):  # queue list is used for returning the items from the list
        return self.items
Exemple #8
0
def HashingFile():  # hashing function is used for hashing the file

    hash = Hashing()  # object is created for the class
    llist = LinkedList()
    it = ReadFile("key")  # data is read from the file
    data = []  # file data is iterated below and appended in the data array
    for i in it:
        data.append(int(i))
    # print(data)
    try:  # try function is used for catching the exceptions to handle exceptions
        for i in data:  # we have added data in hash table by calling insert function
            hash.Insert(i)
        for i in hash.Print():  # now hash file is add to the liked list
            llist.Add(i)
        # print(hash.print())  # hash table will print
        llist.Print()  # now linked list from hash table will be printed

    except AttributeError:  # if any error it will below statement
        print("please check the class file ")
Exemple #9
0
def Company_Shares():
    global user

    st = Stock("stock_json")  # object is created for stock and linked list
    llist = LinkedList()

    with open("stock_json") as f:  # json file is loaded
        data = json.load(f)
    for items in data:  # json file is converted in linked list
        llist.Add(items)
    # input is taken from the user
    while True:
        try:  # try is used for the finding exception

            for i in range(len(st.Only_Stocks())):  # will display all the stocks in the portfolio
                print("**", st.Only_Stocks()[i], end=" ")
            print("\nchoose from above stocks to delete stocks ")
            user = int(input("enter 1 to add or enter 2 to delete or enter 3 to exit :"))

            if user >= 4 or user <= 0:
                print("check input")
                continue
            if user == 1:
                llist.Add(st.Buy()[1])  # if user is given 1 we will ad the stock to the linked list
                llist.Print()
            elif user == 2:
                g = st.Sell()  # if user is given 2 we will call stock class to delete the data
                llist.Remove(data[g])  # here data is removed
                print("stock is removed")
            else:
                print("bye bye")  # program will end here
            st.Dump("stock_json")
            break
        except ValueError:
            print(" please check the Value Error ")
Exemple #10
0
    def test_orderedlist(self):  # function is made

        llist = LinkedList()  # linked list is called
        order = OrderedList()  # results is stored in var
        self.assertEqual(order, llist.Size())  # here data is checked
Exemple #11
0
 def __init__(self):
     self.items = []
     self.ul = LinkedList()
    def test_calender_using_linked_list(self):  # test function is created

        llist = LinkedList()  # linked list is called and object is created
        calen = Calender_Using_Linked_List()  # here results are stored in var
        self.assertEqual(calen, llist.Size())  # validation is done by comparing with answer
Exemple #13
0
    def test_hashingfile(self):     # this function is created to check the program

        llist = LinkedList()    # linked list
        file = HashingFile()    # here program results are stored in the var
        self.assertEqual(file, llist.Size())    # now file and var is compared
 def test_unorderedlist(self):
     llist = LinkedList()
     unorder = UnorderedlList()
     self.assertEqual(unorder, llist.Size())  # here data is cross verify
Exemple #15
0
 def __init__(
     self
 ):  # queue is used for linked list as linked list is called in queue
     self.ul = LinkedList()
     self.items = []
    def test_anagram_queue(
            self):  # test function made for checking the program

        llist = LinkedList()  # linked list is imported
        ana = Anagram_Reversed()  # here function is stored in var
        self.assertEqual(ana, llist.Size())  # here we validated the program
Exemple #17
0
def Company_Shares():
    global add, remove
    st = Stock("stock_json")  # object is created for stock and linked list
    llist = LinkedList()
    stack = Stack()
    q = Queue1()

    with open("stock_json") as f:  # json file is loaded
        data = json.load(f)

    while True:
        try:  # try is used for the finding exception
            userinput = int(
                input("number of stocks you want to Buy or Sell : "))
            if userinput >= 5 or userinput <= 0:
                print("user input should be between 0-5")
                continue

            for i in range(userinput):
                # input is taken from the user
                for stocks in range(len(st.Only_Stocks())):
                    print(st.Only_Stocks()[stocks], end="--"
                          )  # will display all the stocks in the portfolio

                while True:
                    user = int(
                        input(
                            "\nenter 1 to add \nenter 2 to delete \nenter 3 to exit :"
                        ))
                    if user >= 4 or user <= 0:
                        print("enter between 0-4")
                        continue
                    break

                if user == 1:
                    added = st.Buy()[1]
                    stack.Push(added)
                    print()
                    llist.Add(
                        stack.Size()[0]["stock"]
                    )  # if user is given 1 we will ad the stock to the linked list
                    now = datetime.datetime.now()
                    q.AddRear(now)

                elif user == 2:
                    remove = st.Sell()
                    stack.Push(data[remove])
                    llist.Add(stack.Size()[0]["stock"])
                    now1 = datetime.datetime.now()
                    q.AddRear(now1)

                else:
                    print("bye bye")  # program will end here

            llist.Print(
            )  # final linked list is printed with the symbol which were added o removed
            print()
            q.PrintList(
            )  # final linked list is printed from queue function where time stamp of the add or remove is
            # updated

            st.Dump(
                "stock_json"
            )  # this method is used for appending the data in JSON format
            break

        except (ValueError, TypeError):
            print(" please check the  Error ")