Ejemplo n.º 1
0
 def setUp(self):
     """
     method called for performing the tests, Creation
     of the test linked list
     """
     self.liste1 = linkedList.LinkedList()
     self.liste2 = linkedList.LinkedList(["g", "c", "f"])
Ejemplo n.º 2
0
def main():
    # creates cells to build lists
    a = cell.Cell(4)
    b = cell.Cell(3, a)
    c = cell.Cell(2, b)
    d = cell.Cell(1, c)
    e = cell.Cell(9)
    f = cell.Cell(8, e)
    g = cell.Cell(7, f)
    h = cell.Cell(6, g)
    i = cell.Cell(5, h)

    # prints list A
    A = linkedList.LinkedList(d)
    print "list A:"
    A.echo()

    # prints list B
    B = linkedList.LinkedList(i)
    print "list B:"
    B.echo()

    # prints the concatenated list
    X = list_concat_copy(A, B)
    print "concatenation:"
    X.echo()

    # demonstrates that changing A does not affect X
    print "changing A:"
    A = B
    A.echo()
    print "concatenation is unaffected:"
    X.echo()
Ejemplo n.º 3
0
def main():
    # creates cells to build lists
    a = cell.Cell(4)
    b = cell.Cell(3, a)
    c = cell.Cell(2, b)
    d = cell.Cell(1, c)
    e = cell.Cell(9)
    f = cell.Cell(8, e)
    g = cell.Cell(7, f)
    h = cell.Cell(6, g)
    i = cell.Cell(5, h)
    z = cell.Cell(0)

    # prints list A
    A = linkedList.LinkedList(d)
    print "list A:"
    A.echo()

    # prints list B
    B = linkedList.LinkedList(i)
    print "list B:"
    B.echo()

    # prints the concatenated list
    X = list_concat(A, B)
    print "concatenation:"
    X.echo()
Ejemplo n.º 4
0
 def createAdjList(self):
     for vert in self.vertList:
         id = vert.getId()
         newList = linkedList.LinkedList()
         self.adjList.append(newList)
         for e in self.edgeList:
             edgeName = e.getEdgeDesc()
             if edgeName[0].getId() == id:
                 newList.addLink({
                     'vertex': edgeName[1],
                     'weight': e.getEdgeWeight()
                 })
             elif edgeName[1].getId() == id:
                 newList.addLink({
                     'vertex': edgeName[0],
                     'weight': e.getEdgeWeight()
                 })
Ejemplo n.º 5
0
def list_concat_copy(A, B):
    z = cell.Cell(A.first.data)
    C = linkedList.LinkedList(z)

    # iterates through list A, copying all data to C
    current = A.first
    while current.next != None:
        current = current.next
        y = cell.Cell(current.data)
        C.add(y)

    # iterates through list B
    z = cell.Cell(B.first.data)
    C.add(z)
    current = B.first
    while current.next != None:
        current = current.next
        y = cell.Cell(current.data)
        C.add(y)

    return C
Ejemplo n.º 6
0
    def showLeaderboard(self):
        for line in open("quizzes.txt", "r").readlines():
            data = line.split(',')

            for i in range(len(data) - 1):
                print("\t" + str(i + 1) + ". " + str(data[i]))
        # -------------- LINKED LIST USED HERE --------------
        self.leaderBoard = linkedList.LinkedList()
        self.getallmarks()
        # -------------- SELECTION SORT USED HERE --------------
        self.leaderBoard.selectionSort()
        select = int(input("\tEnter Your Option:"))
        quizname = data[select - 1]
        for i in range(self.leaderBoard.getCount() - 1):
            for line in open("lb.txt", "r").readlines():
                datax = line.split(',')
                if (quizname == datax[0]):
                    if (str(self.leaderBoard.returnNthfromfirst(i + 1)) == str(
                            datax[3])):
                        print("\t" + str(datax[1]) + "   |   " +
                              str(datax[2]) + "   |   " + str(datax[3]))
        choice = int(input("Press 1. Search By ID\n Press 2. Back: \n"))
        if (choice == 1):
            ids = []
            if os.path.exists("lb.txt"):
                for line in open("lb.txt", "r").readlines():
                    data = line.split(',')
                    ids.append(int(data[1]))
            ID = int(input("\t Enter Your ID"))
            if (linearsearch(ids, ID) == -1):
                print("\tNot Found")
            else:
                for line in open("lb.txt", "r").readlines():
                    datax = line.split(',')

                    if (int(datax[1]) == ID):
                        print("\t" + str(datax[1]) + "   |   " +
                              str(datax[2]) + "   |   " + str(datax[3]))
Ejemplo n.º 7
0
import linkedList


def kthMember(lList, k):
    temp = []
    n = lList.head

    while (n != None):
        temp.append(n.data)
        n = n.next

    return temp[-k]


myHeadNode = linkedList.Node(1)
myHeadNode.appendToTail(2)
myHeadNode.appendToTail(1)
myHeadNode.appendToTail(3)
myHeadNode.appendToTail(2)
myHeadNode.appendToTail(4)
myHeadNode.appendToTail(3)

myLinkedList = linkedList.LinkedList(myHeadNode)
print('--- 連結リスト L ---')
myLinkedList.printLinkedList()

print('Lの後ろから3番目の要素は' + str(kthMember(myLinkedList, 3)) + 'です。')
Ejemplo n.º 8
0
from multiprocessing import Process, Queue

import mysql_queries as mysql
import iptablelib
import portmanagerlib
import logmanager
import sys
import time
import linkedList

iptables = iptablelib.IpTablesLib('100.61.0.1', '10.1.1.199')
iptables.installIpTableNorth('10.1.1.77', 8000, 25000)
portmanager = portmanagerlib.PortManager()
log_m = logmanager.LogManager()
log = log_m.logger()
l = linkedList.LinkedList()
""" """


def install_iptables(sessions):
    for item in sessions:
        session = sessions[item]
        ssh_port = mysql.mysql_query_port_no(str(session['username']))
        iptables.installIpTableSouth(str(session['local_ip']), 22, ssh_port)


""" """


def delete_iptables(sessions):
    for item in sessions:
Ejemplo n.º 9
0
def p1():  # dummy function
    problem1.list_concat(A, B)


def p2():  # dummy function
    problem2.list_concat_copy(C, D)


# creates four lists to use concatenation functions on
# the outer loop handles the different data sizes and
# the inner loop actually adds the cells to each list
x = 0
f = open('mydata.txt', 'w')
for count in range(1, 16):
    A = linkedList.LinkedList(cell.Cell(x))
    B = linkedList.LinkedList(cell.Cell(x))
    C = linkedList.LinkedList(cell.Cell(x))
    D = linkedList.LinkedList(cell.Cell(x))
    for num in range(1, count * 1000):
        A.add(cell.Cell(x))
        B.add(cell.Cell(x))
        C.add(cell.Cell(x))
        D.add(cell.Cell(x))

    # code to time execution, using the dummy functions above
    # in order to avoid passing arguments
    mytime = timeit.Timer('p1()', 'from __main__ import p1')
    delta = mytime.timeit(1)
    mytime2 = timeit.Timer('p2()', 'from __main__ import p2')
    epsilon = mytime2.timeit(1)
Ejemplo n.º 10
0
                return None
            else:
                if pNode in p:
                    return pNode
                else:
                    p.append(pNode)
                    pNode = pNode.next


if __name__ == "__main__":
    # 测试实例
    import sys
    sys.path.append("..")
    sys.path.append("./")
    import linkedList as l
    link = l.LinkedList()
    for x in [1, 2, 3, 4, 5, 6]:
        link.append(x)
    link.traverse()
    # link.head.next = link.head
    link.head.next.next.next.next.next.next = link.head.next.next.next
    n = 20
    p = link.head
    t = []
    while n:
        t.append(p.item)
        p = p.next
        n -= 1
    print(t)

    f = Solution()
Ejemplo n.º 11
0
class User:
    leaderBoard = linkedList.LinkedList()

    def __init__(self, userid, name, email, quizattempts, quizwon):
        self.userid = userid
        self.name = name
        self.email = email
        self.quizattempts = quizattempts
        self.quizwon = quizwon

    def userHome(self):
        stack.push(self.userHome)
        while (True):
            print('\n\t\t***********************************************')
            print("\t\t          " + self.name.capitalize() +
                  "! Welcome To Quiz App ")
            print('\t\t***********************************************')
            menu = {
                "1": "Start Quiz",
                "2": "Your Quizzes History",
                "3": "LeaderBoard",
                "4": "Log Out"
            }
            for key, value in menu.items():
                print("\t\t {}. {}".format(key, value))
            select = input("\tEnter Your Selection (1-4): ")
            if select == '1':
                self.selectQuiz()
            elif select == '2':
                self.showQuizHistory()
            elif select == '3':
                self.showLeaderboard()
            elif select == '4':
                stack.pop()()
            else:
                print('NOTE: SELECT CORRECT ACTION\n')

    def register(self):
        # will create Users.txt file it doen't already exists
        file = open("Users.txt", "a+")
        if (self.userAlreadyExist() == False):
            file.write(
                str(self.userid) + "," + str(self.name) + "," +
                str(self.email) + "," + str(self.quizattempts) + "," +
                str(self.quizwon) + "\n")
            print("\tSuccessFully Registered")
            file.close()
        else:
            print('\tThis ID is Already in Use')

    def userAlreadyExist(self):
        usersids = []

        if os.path.exists("Users.txt"):
            for line in open("Users.txt", "r").readlines():
                data = line.split(',')
                usersids.append(data[0])
        else:
            stack.pop()()

        # -------------- BUBBLE SORT USED HERE --------------
        bubbleSort(usersids)
        # -------------- BINARY SEARCH USED HERE --------------
        if (binarySearch(usersids, 0,
                         len(usersids) - 1, self.userid) == False):
            return False
        else:
            return True

    def login(self):
        flag = 404
        admin = Admin()
        if (int(self.userid) == int(admin.Id)
                and str(self.name) == str(admin.name)):
            admin.menu()
        else:
            if (os.path.exists("Users.txt")):
                for line in open("Users.txt", "r").readlines():
                    data = line.split(',')
                    if (self.userid == data[0] and self.name == data[1]):
                        self.userid = data[0]
                        self.name = data[1]
                        self.email = data[2]
                        self.quizattempts = data[3]
                        self.quizwon = data[4]
                        self.userHome()
                    else:
                        flag = 404
            else:
                print("Error: No user found")
                stack.pop()()
        if (flag == 404):
            print("User doesn't Exist")

    def isAlreadyAttempted(self, quizname):
        file = str(self.userid) + "history.txt"
        if (os.path.exists(file)):
            for line in open(file, "r").readlines():
                data = line.split(',')
                if (quizname == data[0]):
                    return True
                else:
                    return False
        else:
            return False

    def showLeaderboard(self):
        for line in open("quizzes.txt", "r").readlines():
            data = line.split(',')

            for i in range(len(data) - 1):
                print("\t" + str(i + 1) + ". " + str(data[i]))
        # -------------- LINKED LIST USED HERE --------------
        self.leaderBoard = linkedList.LinkedList()
        self.getallmarks()
        # -------------- SELECTION SORT USED HERE --------------
        self.leaderBoard.selectionSort()
        select = int(input("\tEnter Your Option:"))
        quizname = data[select - 1]
        for i in range(self.leaderBoard.getCount() - 1):
            for line in open("lb.txt", "r").readlines():
                datax = line.split(',')
                if (quizname == datax[0]):
                    if (str(self.leaderBoard.returnNthfromfirst(i + 1)) == str(
                            datax[3])):
                        print("\t" + str(datax[1]) + "   |   " +
                              str(datax[2]) + "   |   " + str(datax[3]))
        choice = int(input("Press 1. Search By ID\n Press 2. Back: \n"))
        if (choice == 1):
            ids = []
            if os.path.exists("lb.txt"):
                for line in open("lb.txt", "r").readlines():
                    data = line.split(',')
                    ids.append(int(data[1]))
            ID = int(input("\t Enter Your ID"))
            if (linearsearch(ids, ID) == -1):
                print("\tNot Found")
            else:
                for line in open("lb.txt", "r").readlines():
                    datax = line.split(',')

                    if (int(datax[1]) == ID):
                        print("\t" + str(datax[1]) + "   |   " +
                              str(datax[2]) + "   |   " + str(datax[3]))

    def getallmarks(self):
        if (os.path.exists("lb.txt")):
            for line in open("lb.txt", "r").readlines():
                data = line.split(",")
                self.leaderBoard.push(int(data[3]))

    def LeaderBoard(self, quizname, score):
        file = "lb.txt"
        f = open(file, "a+")
        f.write(
            str(quizname) + "," + str(self.userid) + "," + str(self.name) +
            "," + str(score) + ",\n")

    def showQuizHistory(self):
        file = str(self.userid) + "history.txt"
        print("\n")
        if (os.path.exists(file)):
            for line in open(file, "r").readlines():
                data = line.split(',')
                print("\t" + str(data[0]) + "   |   " + str(data[1]))
                self.searchQuizHistory(data)
        else:
            print('\tNo Quiz History Found Please attempt any Quiz')

        str(input("\n\tPress Any Key"))

    def searchQuizHistory(self, data):
        value = input("Enter Name of the Quiz")
        file = str(self.userid) + "history.txt"
        print("\n")
        if (os.path.exists(file)):
            for line in open(file, "r").readlines():
                data = line.split(',')
                # -------------- LINEAR USED HERE --------------
                if (linearsearch(data[0], value) != False):
                    print(linearsearch(data[0], value))
                else:
                    print("Value not found")
        else:
            print('\tNo Quiz History Found Please attempt any Quiz')

        str(input("\n\tPress Any Key"))

    def saveQuizHistory(self, quizname, score):
        filename = str(self.userid) + "history.txt"
        f = open(filename, "a+")
        f.write(str(quizname) + "," + str(score) + ",\n")

    def selectQuiz(self):
        i = 0
        for line in open("quizzes.txt", "r").readlines():
            data = line.split(',')

            for i in range(len(data) - 1):
                print("\t" + str(i + 1) + ". " + str(data[i]))

        select = int(input("\tEnter Your Option:"))
        if (select < i + 1):
            if (self.isAlreadyAttempted(data[select - 1]) == True):
                print(
                    "\tYou have Already Attempted This Quiz Please Try another"
                )
                str(input("\tPress Any Key "))
                self.userHome()
            else:
                str(input("\tDo You Really want to Start ? "))
                quizname = data[select - 1]
                filename = data[select - 1] + ".txt"
                questionnumber = 0
                marks = 0
                if (os.path.exists(filename)):
                    for line in open(filename, "r").readlines():
                        data = line.split(',')
                        questionnumber += 1
                        print("\tQuestion Number " + str(questionnumber))
                        print("\t" + data[1])
                        print("\t\t1.  " + data[2])
                        print("\t\t2.  " + data[3])
                        print("\t\t3.  " + data[4])
                        print("\t\t4.  " + data[5])

                        answer = int(input("\tEnter Your Option Number: "))
                        answer += 1
                        if (data[answer] == data[6]):
                            marks += 1
                else:
                    print("Quiz doesn't Exist")
                result = int((marks / questionnumber) * 100)
                self.LeaderBoard(quizname, result)
                self.saveQuizHistory(quizname, result)
                print("\t Your Result is: " + str(result))
        else:
            print("Select correct option")
Ejemplo n.º 12
0
#!/usr/bin/python

import sys
import cell
import linkedList
import problem1

a = cell.Cell(4)
b = cell.Cell(3, a)
c = cell.Cell(2, b)
d = cell.Cell(1, c)
e = cell.Cell(9)
f = cell.Cell(8, e)
g = cell.Cell(7, f)
h = cell.Cell(6, g)
i = cell.Cell(5, h)

L = linkedList.LinkedList(d)
M = linkedList.LinkedList(i)
#L.echo()
#M.echo()

X = problem1.list_concat(L, M)
#X.echo()
Ejemplo n.º 13
0
	def my_list(self):
		return linkedList.LinkedList()