美文网首页
Part Ⅲ Elementary Data Structure

Part Ⅲ Elementary Data Structure

作者: 綿綿_ | 来源:发表于2017-01-12 16:53 被阅读0次

    Stacks

    last-in, first-out (LIFO)

    insertion operation: Push
    deletion operation:Pop

    If an empty stack is popped, then stack underflows
    If top[S ] exceeds n, then stack overflows.

    Pseudo code of stack empty

     STACK -EMPTY
    if  top[S]=0
     then  return  ture
    else  return  false
    
     PUSH(S, x)
      top[S]←top [S ]+1
      S[top[S]]←x
    
    Pop(S)
    if STACK-EMPTY(S)
       then error "underflows"
    else top[S] ←top[S]-1
       return S[top[S]+1]
    

    Each of the three stack operations takes Ο(1) tim.

    Queue
    First in, first out( FIFO)

    Enqueue (Q, x )
    
    Q[tail[Q]]←x
    if tail[Q]=length[Q]
       then tail[Q]←1
      else tail[Q]←tail[Q]+1
    
    Dequeue(Q)
    
    x←Q[head[Q]]
    if head[Q]=length [Q]
       then head[Q]=1
    else head[Q]←head[Q]+1
       return x
    

    Inserting into a linked list

    LIST -Insert (L, x)
    next [x ]←head [L]
    if head [L]≠NIL 
    then prev [head [L ]]←x 
    head [L]←x 
    prev [x]←NIL
    

    相关文章

      网友评论

          本文标题:Part Ⅲ Elementary Data Structure

          本文链接:https://www.haomeiwen.com/subject/mpikmttx.html