zoukankan      html  css  js  c++  java
  • 顺序栈创建

     1 /*
     2 顺序栈的创建
     3 
     4 Levi.
     5 */
     6 
     7 #include <stdio.h>
     8 #define DataType char
     9 #define StackSize 100
    10 
    11 
    12 typedef struct{
    13     DataType stack[StackSize];
    14     int top;
    15 }SeqStack;
    16 
    17 
    18 void InitStack(SeqStack *S){
    19     S->top=0;
    20 }
    21 
    22 int StackEmpty(SeqStack S){
    23     if(S.top==0)
    24               return 1;
    25     else
    26               return 0;
    27 }
    28 
    29 int GetTop(SeqStack S,DataType *e){
    30     if(S.top<=0){
    31               printf("null!\n");
    32               return 0;
    33     }
    34     else{
    35         *e=S.stack[S.top-1];
    36         return 1;
    37     }
    38 }
    39 
    40 int PushStack(SeqStack *S,DataType e){
    41     if(S->top>=StackSize){
    42         printf("Fail !\n");
    43         return 0;
    44     }
    45     else{
    46         S->stack[S->top]=e;
    47         S->top++;
    48         return 1;
    49     }
    50 }
    51 
    52 int PopStack(SeqStack *S,DataType *e){
    53     if(S->top<=0){
    54         printf("Fail !\n");
    55         return 0;
    56     }
    57     else{
    58         S->top--;
    59         *e=S->stack[S->top];
    60         return 1;
    61         
    62     }
    63 }
    64 
    65 int StackLength(SeqStack S){
    66     return S.top;
    67 }
    68 
    69 void ClearStack(SeqStack *S){
    70     S->top=0;
    71 }
    72 
    73 void conversion(){
    74     SeqStack s;
    75     unsigned n;
    76     int e;
    77     InitStack(&s);
    78     printf("n converse %d jinzhi,Please input : n(>=0)=",2);
    79     scanf("%u",&n);
    80     while(n){
    81         PushStack(&s,n%2);
    82         n=n/2;
    83     }
    84 
    85     while(!StackEmpty(s)){
    86         PopStack(&s,&e);
    87         printf("%d",e);
    88     }
    89     printf("\n");
    90 }
    91 
    92 void Print(SeqStack s){
    93     int base=0;
    94     while(base<s.top){
    95         printf("%c",s.stack[base]);
    96         base++;
    97     }
    98 }
  • 相关阅读:
    (SPOJ4)Transform the Expression
    Minix2.0操作系统kernel文件分析
    Minix2.0内核源代码的组织结构
    powerdesigner教程系列(三)
    多线程
    软件架构师成长之路
    保护sqlconnection的链接字符串中的密码不泄露
    powerdesigner教程系列(四)
    [Serializable]在C#中的作用.NET 中的对象序列化
    vps经典文章
  • 原文地址:https://www.cnblogs.com/suiyun/p/2875307.html
Copyright © 2011-2022 走看看