鱼C论坛

 找回密码
 立即注册
查看: 1960|回复: 2

一个栈在第二次输出栈时,栈为空栈, 如果需要保持之前栈的原样,应该如何修改程序?

[复制链接]
发表于 2021-11-27 17:28:51 | 显示全部楼层 |阅读模式
50鱼币
#include<stdio.h>
#include "intstack.h"

void PrintStack(SqStack &S){
    SElemType e;
    while(!StackEmpty(S))
     {   Pop(S,e);  
printf("%3d",e);
}
    printf("\n");      
}/*Pop_and_Print*/

int CreateStack(SqStack &S){
    int e;
    if(InitStack(S))
      {printf("初始化栈成功!\n");
      prt_base_top_length(S);
      }  
    else{
        printf("初始化失败!\n");
        return ERROR;
    }
    printf("\n输入需要入栈的各个整数:(Terminated by inputing a character)\n");
           while(scanf("%d",&e))
    {         Push(S,e);
        prt_base_top_length(S);
     };
    return OK;
}/*CreateStack*/


int main(){
    SqStack ss;
    printf("1-建立栈\n");
    CreateStack(ss);
    printf("\n2-出栈并打印\n");
    prt_base_top_length(ss);
        PrintStack(ss);
    prt_base_top_length(ss);
    PrintStack(ss);
    return 0;
}          

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-11-28 14:32:16 | 显示全部楼层
  1. $ gcc -g -Wall -o main main.c
  2. main.c:2:10: fatal error: intstack.h: No such file or directory
  3.     2 | #include "intstack.h"
  4.       |          ^~~~~~~~~~~~
  5. compilation terminated.
  6. $
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-3 16:39:12 | 显示全部楼层
那你为什么还要用栈?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-26 00:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表