示例#1
0
 def in_graph(self, v):
     assert isinstance (v, Vertex)
     for pair in self.get_adjacency_list():
         vertex = pair [0]
         if ((vertex.get_value() == v.get_value()) == True):
             return True
     return False
示例#2
0
    def find_pair (self, v):

        assert isinstance (v, Vertex)

        #1 for looking up pair
        #1 for calling get_adjacency_list()
        self.__time_op += 2
        #1 for storing pair
        #1 for storing adjacency_list()
        self.__space_op += 2

        for pair in self.get_adjacency_list():
            
            #1 for looking up vertex
            #1 for looking pair
            #1 for looking up 0th index of pair
            self.__time_op += 3
            #1 for storing vertex
            self.__space_op += 1

            vertex = pair [0]

            #1 for looking up vertex
            #1 for calling get_value()
            #1 for looking up v
            #1 for calling get_value()
            #1 for comparing values
            #1 for comparing against True
            self.__time_op += 6

            if ((vertex.get_value() == v.get_value()) == True):
                #1 for looking up pair
                #1 for returning pair
                self.__time_op += 2
                return pair

            #1 for looking up pair
            #1 for calling get_adjacency_list()
            self.__time_op += 2
            #1 for storing pair
            #1 for storing adjacency_list()
            self.__space_op += 2

        #1 for returning False
        self.__time_op += 1
        return False