当前位置: 首页>>代码示例>>Python>>正文


Python LinkedList.add方法代码示例

本文整理汇总了Python中LinkedList.LinkedList.add方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.add方法的具体用法?Python LinkedList.add怎么用?Python LinkedList.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinkedList.LinkedList的用法示例。


在下文中一共展示了LinkedList.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LLQueue

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
class LLQueue(object):
    def __init__(self, size=0):
        self._list = LinkedList()
        self._size = size

    def enqueue(self, data):
        if (self._size > 0 and self._list.count < self._size):
            self._list.add(data)
        else:
            raise Exception("Too many items in the queue")

    def dequeue(self):
        if (self._list.count == 0):
            raise Exception("No items in the queue")
        node = self._list[0]
        del self._list[0]
        return node

    def isEmpty(self):
        return (self._list.count == 0)

    def clear(self):
        self._list.clear()

    @property
    def size(self):
        return self._size

    def __len__(self):
        return len(self._list)
开发者ID:bertothunder,项目名称:coursera-algorithms,代码行数:32,代码来源:LLQueue.py

示例2: __init__

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
class Queue:
    def __init__(self):
        self.__elements = LinkedList()

    # Adds an element to this queue
    def enqueue(self, e):
        self.__elements.add(e)
    
    # Removes an element from this queue
    def dequeue(self):
        if self.getSize() == 0:
            return None
        else:
            return self.__elements.removeAt(0)
    
    # Return the size of the queue
    def getSize(self):
        return self.__elements.getSize()
    
    # Returns a string representation of the queue
    def __str__(self):
        return self.__elements.__str__()

    # Return true if queue is empty 
    def isEmpty(self):
        return self.getSize() == 0
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:28,代码来源:Queue.py

示例3: read_file

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
def read_file(file):
    '''
    Read CSV File, Important Only Read column 1 and column 2
    
    Parameters
    ----------
    file : str, path of file 
        path for file to read and fill dataset
    
    Returns
    -------
    dataset: LinkedLink dataset
    '''
    #Open File
    with open(file, 'rb') as csvfile:
        reader = csv.reader(csvfile)
        dataset=LinkedList()
        #for row in file:
        for row in reader:
                #if length of row >= 2:
                if len(row) >= 2:
                    #add to LinkedList Float Row[0] and Row[1]
                    try:
                        dataset.add(( float(row[0]) , float(row[1]) ))
                    except ValueError:
                        log.warning("%s Problem whit row" % row[0])
                else:
                    #mesnsaje: row whit insuficient data.
                    log.warning("row whit insuficient data or Empty Row")
        return dataset
开发者ID:arpagon,项目名称:assignaments,代码行数:32,代码来源:fit.py

示例4: sum_list

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
def sum_list(l1, l2):
  """
  returns a list which contains the addition of input two lists.
  """
  lsum = LinkedList()
  carry = 0
  l1_node = l1.head
  l2_node = l2.head

  while l1_node or l2_node:
    val = carry
    if l1_node:
      val += l1_node.value
      l1_node = l1_node.next

    if l2_node:
      val += l2_node.value
      l2_node = l2_node.next

    lsum.add(val % 10)
    carry = val / 10
  if carry:
    lsum.add(carry)

  return lsum
开发者ID:vivekkeshore,项目名称:ctci,代码行数:27,代码来源:list_sum_2_5.py

示例5: test_1

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
 def test_1(self):
     A = LinkedList()
     A.add(1)
     A.add(2)
     A.add(6)
     A.add(3)
     res = s.recursive_search(A, 2)
     self.assertIsNot(res,None)
开发者ID:smwade,项目名称:ACME-1,代码行数:10,代码来源:testcases.py

示例6: test_deleteNone

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
 def test_deleteNone(self):
     l = LinkedList(1)
     l.add(2)
     l.add(3)
     l.delete(5)
     self.assertEquals(l.val, 1)
     self.assertEquals(l.next.val, 2)
     self.assertEquals(l.next.next.val, 3)
开发者ID:jackchi,项目名称:interview-prep,代码行数:10,代码来源:test_linkedList.py

示例7: test_add

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
 def test_add(self):
     l = LinkedList(0)
     l.add(1)
     l.add(2)
     l.add(3)
     self.assertEquals(0, l.val)
     self.assertEquals(1, l.next.val)
     self.assertEquals(2, l.next.next.val)
     self.assertEquals(3, l.next.next.next.val)
开发者ID:jackchi,项目名称:interview-prep,代码行数:11,代码来源:test_linkedList.py

示例8: test_add

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
    def test_add(self):
        myLinkedList = self.getLinkedList()
        myLinkedList.add(-1)
        self.assertEqual(myLinkedList.toArray()[0], Node(-1).getData())

        # test empty list
        myLinkedList = LinkedList()
        myLinkedList.add(-1)
        self.assertEqual(myLinkedList.toArray()[0], Node(-1).getData())
开发者ID:avihoo,项目名称:singly-linked-list,代码行数:11,代码来源:TestLinkedList.py

示例9: linked_list_test

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
    def linked_list_test(self):
        """Test that the singly linked list is able to correctly append items. Asserts that the list contains all items
        AND that the items are int he correct order.
        """
        items = range(-10, 10)                      # randomly ordered list
        shuffle(items)

        linked_list = LinkedList()                  # linked list containing same items in same order
        for item in items:
            linked_list.add(item)

        ll_items = [x for x in linked_list.next()]  # contents of linked list as a python list
        self.assertEqual(ll_items, items)           # test that the contents and order are the same as the original list
开发者ID:Clarksj4,项目名称:Algorithms_and_Data_Structures,代码行数:15,代码来源:test.py

示例10: reverse_list_test

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
    def reverse_list_test(self):
        """Test the the linked list is correctly able to reverse the order of items within itself. Asserts that the list
        has the correct ordering of items after being reversed AND after being reversed a second time.
        """
        items = range(1, 10)                        # test list of items ( numbers 1 - 10)

        linked_list = LinkedList()
        for item in items:                          # add each test item to linked list
            linked_list.add(item)

        linked_list.reverse()                       # reverse order of both lists
        items = reversed(items)
        for ll_item, item in zip(linked_list.next(), items):    # check that each index holds same item
            self.assertEqual(ll_item, item)

        linked_list.reverse()                       # reverse linked list again
        for ll_item, item in zip(linked_list.next(), range(1, 10)):    # check that each index holds same item
            self.assertEqual(ll_item, item)
开发者ID:Clarksj4,项目名称:Algorithms_and_Data_Structures,代码行数:20,代码来源:test.py

示例11: LLStack

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
class LLStack(object):
	def __init__(self):
		self._list = LinkedList()

	def push(self, data=None):
		self._list.add(data)

	def pop(self):
		try:
			node = self._list[-1]
			del self._list[-1]
			return node.data
		except IndexError:
			# Mimicing the array error message
			raise IndexError("pop from empty stack")

	def __len__(self):
		return len(self._list)
开发者ID:bertothunder,项目名称:coursera-algorithms,代码行数:20,代码来源:LLStack.py

示例12: __init__

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
class EdgeDB:
    def __init__(self):
        self.list = LinkedList()
        self.totalEdge = 0

    def addEdge(self, n):
        self.list.add(None, n)                  # Need to check for duplicates
        self.totalEdge += 1

    def deleteUser(self, id):
        l = []
        user = []
        count = 0
        pre = None
        n = self.list.start
        while n:
            if (n.v.A == id) or (n.v.B == id):  # If either A or B is the UserID
                if n.v.B == id:                 # If Followed user(B) matches, stash the follower
                    user.append(n.v.A)
                else:                           # If Following user(A) matches, count
                    count += 1
                if pre:                         # Actual delete process
                    pre.next = n.next
                    n = n.next
                else:
                    self.list.start = n.next
                    n = self.list.start
                self.totalEdge -= 1             # Update
            else:
                pre = n
                n = n.next
        l.append(user)
        l.append(count)
        return l    # [List of UserID following the input, # of Users which the input follows]

    def getFollowID(self, id):
        l = []
        n = self.list.start
        while n:
            if n.v.A == id:
                l.append(n.v.B)
            n = n.next
        return l
开发者ID:Rikuforever,项目名称:2011171061_LHJ,代码行数:45,代码来源:DB.py

示例13: sum_lists

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
def sum_lists(ll_a, ll_b):
    n1, n2 = ll_a.head, ll_b.head
    ll = LinkedList()
    carry = 0
    while n1 or n2:
        result = carry
        if n1:
            result += n1.value
            n1 = n1.next
        if n2:
            result += n2.value
            n2 = n2.next

        ll.add(result % 10)
        carry = result // 10

    if carry:
        ll.add(carry)

    return ll
开发者ID:5imp1e,项目名称:CtCI-6th-Edition-Python,代码行数:22,代码来源:5_Sum_Lists.py

示例14: read_file

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
def read_file(file):
    '''
    Read CSV File, Important Only Read column 1
    
    :param file: path for file to read 
    :returns dataset: LinkedLink dataset
    '''
    with open(file, 'rb') as csvfile:
        #dialect = csv.Sniffer().sniff(csvfile.read(1024))
        #csvfile.seek(0)
        reader = csv.reader(csvfile)
        dataset=LinkedList()
        for row in reader:
                if len(row) >= 1:
                    try:
                        dataset.add(float(row[0]))
                    except ValueError:
                        log.warning("%s Is not a float" % row[0])
                else:
                    log.warning("Empty Row")
        return dataset
开发者ID:arpagon,项目名称:assignaments,代码行数:23,代码来源:mean_std.py

示例15: getLinkedList

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import add [as 别名]
    def getLinkedList(self):
        myLinkedList = LinkedList()
        for i in range(0, 10):
            myLinkedList.add(i)

        return myLinkedList
开发者ID:avihoo,项目名称:singly-linked-list,代码行数:8,代码来源:TestLinkedList.py


注:本文中的LinkedList.LinkedList.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。