zoukankan      html  css  js  c++  java
  • [Data Structure]栈&队列的实现

     1 const int maxsize = 1e4 + 5;
     2 struct stack{
     3     int data[maxsize];
     4     int Top;
     5     stack(){Top = -1;}
     6     void clear(){Top = -1;}
     7     bool push(int x){
     8         if(Top == maxsize-1)
     9             return false;
    10 
    11         data[++Top] = x;
    12         return true;
    13     }
    14     bool pop(){
    15         if(Top == -1) return false;
    16         else Top--;
    17     }
    18     int top(){return data[Top];}
    19     bool isempty(){
    20         if(Top == -1)return true;
    21         return false;
    22     }
    23 };
     1 struct queue{
     2     int data[maxsize];
     3     int head, tail;
     4 
     5     queue(){head = tail = 0;}
     6     void clear(){head = tail = 0;}
     7 
     8     int front(){
     9         if(head == tail)
    10             return -1;
    11         else
    12             return data[head];
    13     }
    14 
    15     bool push(int x){
    16         if(tail != maxsize-1)
    17             data[tail++] = x;
    18         else
    19             return false;
    20         return true;
    21     }
    22 
    23     bool pop(){
    24         if(head == tail){
    25             head = tail = 0;
    26             return false;
    27         }
    28         else
    29             head++;
    30         return true;
    31     }
    32 
    33     bool isempty(){
    34         if(head == tail){
    35             head = tail = 0;
    36             return true;
    37         }    
    38         else return false;
    39     }
    40 };
  • 相关阅读:
    realsense d435i qt 测试
    realsense d435i 数据 测试
    realsense d435i测试
    ubuntu torch GPU yolov5
    IfcLayeredItem
    ubuntu大服务器 pytorch环境配置
    condarc内容
    realsense point cloud
    yolov5 环境配置
    pip error
  • 原文地址:https://www.cnblogs.com/leafsblogowo/p/12880412.html
Copyright © 2011-2022 走看看