Data structure of the linear structure (an array [list], the form of the list chain ** CRUD Application linear structure stack queue [** function calls]), linear tree

data structure

Reference: http://lupython.gitee.io/

Linear structure

Is the ability to string together with a line of data structures

 

Array (list)

Q: The array is prerequisite to apply what? a [12]? Memory needs to meet the conditions?

A: The memory must have a continuous memory space

int a [7]: declare an array, this array is the array name a, the size of the array 7, the array element type is an integer. int a [7] = array (1,2,3,4,5,6,7)

Q: How do I apply memory?

Answer: C, C ++ language, application: mallco (28). Release: free (28)

Q: int a [7] = [1,2,3,4,5,6,7] a [3] = 4?

 A: a [3] = the first address (1000) + index (3) Type Length * (4) = 1012 --- 1015 (int type 4 bytes)

Q: Where did the first address of the array get?

A: The first address is stored in an array array name

Increase list (the append) deleted (pop) change (Update) to check (for)

 

List (Joseph, Diushou Juan problems)

 

Single chain CRUD

Code:

# Liangshan heroes leaderboard 
class Hero ():
     DEF  __init__ (Self, NO = None, name = None, the Nickname = None, pNext = None): 
        self.no = NO 
        self.name = name 
        self.nickname = the Nickname     # three is a range 
        self.pNext = pNext   # pointer field, keep the memory address 

DEF the Add (head, Hero):
     # # head node can not move, so temporary variables need third party help head to traverse 
    CUR = head 

    the while cur.pNext! = None:
         # # the memory address of the next node pay cur, cur at this time that would point to the next node 
        cur = cur.pNext 

    ## When the user exits this loop, cur point to the end node has 
    cur.pNext = Hero 

DEF the getAll (head): 
    CUR = head 

    the while cur.pNext =! None: 
        CUR = cur.pNext
         Print ( ' code is:% s, name:% s, nickname is: S% ' % (cur.no, cur.name, cur.nickname)) 

DEF delHero (head, NO): 
    CUR = head 

    the while ! cur.pNext = None:
         IF CUR. == pNext.no NO:
             BREAK 
        CUR = cur.pNext 
    cur.pNext =cur.pNext.pNext 

head = Hero ()    # head node 

h1 of = Hero (. 1, ' Matsue ' , ' timely ' ) 
the Add (head, h1 of) 

H2 = Hero (2, ' Junyi ' , ' XXX ' ) 
the Add ( head, H2) 

H3 = Hero (. 3, ' Ximen ' , ' dsadsad ' ) 
the Add (head, H3) 

the getAll (head) 
delHero (head, 2 )
 Print ( ' *********** ' ) 
the getAll (head)

 

 Joseph solve the problem with the list (to know)

Provided numbered 1,2, ... n, n individuals sitting around the agreed number k (1 <= k <= n) of the number of packets from the beginning person, that person to the number m of the column, its lower and from 1 gettin a number, that person's number to m and the columns, and so on, until everyone out of the line up, thereby generating a sequence number of the team

# 循环链表
class Child(object):
    first = None
    def __init__(self, no = None, pNext = None):
        self.no = no
        self.pNext = pNext
    def addChild(self, n=4):
        cur = None
        for i in range(n):
            child = Child(i + 1)
            if i == 0:
                self.first = child
                self.first.pNext = child
                CUR = self.first
             the else : 
                cur.pNext = Child 
                child.pNext = self.first 
                CUR = cur.pNext
     DEF showChild (Self): 
        CUR = self.first
         the while cur.pNext =! self.first:
             Print ( " child number is: D% " % cur.no) 
            CUR = cur.pNext
         Print ( " a child code is: D% " %cur.no)
     DEF countChild (Self, m, K): 
        tail = self.first
         the while tail.pNext =! self.first: 
            tail = tail.pNext
         # came out already in the foregoing First 
        # start counting from a few people 
        for I in Range (. 1-K ): 
            tail = tail.pNext 
            self.first = self.first.pNext
         # twice the number, and the first is to make a move tail 
        # count of three, it is to make the first move and tail twice 
        while ! = tail self.first:   # when the tail == first description was only one man 
            for iin Range (. 1-m ): 
                tail = tail.pNext 
                self.first = self.first.pNext 
            self.first = self.first.pNext 
            tail.pNext = self.first
         Print ( " last in the left circle of people : D% " % tail.no) 
C = Child () 
c.addChild ( . 4 ) 
c.showChild () 
c.countChild ( 3,2-)
View Code

 

Application of a linear structure

Defined stack: a way to implement "last out" storage structure

 Classification stack

Static stack: The core is an array, similar to a continuous memory array, you can only operate its top element

Dynamic stack: core list

 

 ** call function (operating principle underlying):

 pop

 Judgment: If the stack is empty, the representative of the functions are executed, release the memory

 

queue

Definition: a way to achieve "FIFO" data structure

 Applications such as: producer-consumer model (the concept of the operating system, can be achieved in various languages)

 

Nonlinear structure

The definition of the tree

Simply that:

  • And only one tree root
  • There are several disjoint sub-tree, the tree itself is a sub-tree

Popular definitions:
1. The tree is composed of nodes and edges
2. Each node can have only one parent, but can have multiple child nodes. But there is one exception to the node, the node has no parent, this is called the root node

Jargon tree

  • node
  • Parent
  • Child node
  • Posterity
  • Cousins
  • brothers
  • depth
    • Layers from the root node to node is called the bottom depth, the root node is the first layer
  • Leaf node
    • The node has no children
  • degree
    • Number of child nodes

Classification tree

General tree

  • Any sub-node number of a node B + Tree is not limited

Binary Tree

  • Definition: any of the children of a node number of at most two child nodes and the position can not be changed
    • Full Binary Tree
      • Definition: Under the premise of not increasing the number of layers, you can not add more nodes of a binary tree
      •  
    • Complete binary tree
      • Definition: full binary tree just delete the bottom of the right-most consecutive number of nodes
    • General binary tree

forest

  • n disjoint set of numbers

 

Application tree

  • Tree is a database of important form of data organization
  • The relationship between the operating system itself is the child of the parent tree
  • Inheritance surface type object language class

 

Recommended Books

 

Guess you like

Origin www.cnblogs.com/ludingchao/p/12634469.html