zoukankan      html  css  js  c++  java
  • 行编辑程序

    #include <stdio.h>
    #include<string.h>
    #define maxSize 128
    typedef struct SqStack{
    	char data[maxSize];
    	int top;
    }SqStack;
    void InitStack(SqStack * S){
    	S->top = -1;
    }
    void Push(SqStack * s, char x)
    {
    	if (s->top != maxSize - 1)
    	{
    		s->data[++(s->top)] = x;
    	}
    	else
    	{
    		printf("栈已经溢出!");
    	}
    }
    void Pop(SqStack * S, char e)
    {
    	if (S->top != -1)
    	{
    		e = S->data[S->top];
    		--(S->top);
    	}
    	else{
    		printf("栈为空无法执行出栈操作!");
    	}
    }
    int StackEmpty(SqStack * s)
    {
    	if (s->top == -1)
    		return 1;
    	else return 0;
    }
    void ClearStack(SqStack *S)
    {
    	S->top = -1;
    }
    void DestoryStack(SqStack * S)
    {
    	S->top = -1;
    }
    void PrintStack(SqStack * S)
    {
    	int i = 0;
    	int length = S->top;
    	char str[maxSize];
    	while (S->top != -1)
    	{
    		str[i] = S->data[S->top];
    		S->top--;
    		i++;
    	}
    	printf("正确的数列为:");
    
    	int j, temp;
    	for (j = length, i = 0; j >= 0 && i != j; j--, i++)
    	{
    		temp = str[i];
    		str[i] = str[j];
    		str[j] = temp;
    	}
    	for (i = 0; i <=length; i++)
    	{
    		printf("%c", str[i]);
    	}
    }
    void LineEdit()
    {
    	SqStack * S = new SqStack();
    	InitStack(S);
    	char ch = getchar();
    	while (ch != '
    '){
    		switch (ch){
    		case '#':Pop(S, ch); break;
    		case '@':ClearStack(S); break;
    		default:Push(S, ch); break;
    		}
    		ch = getchar();
    	}
    	PrintStack(S);
    	ClearStack(S);
    	if (ch != EOF) ch = getchar();
    	DestoryStack(S);
    }
    void main()
    {
    	LineEdit();
    	getchar();
    }

  • 相关阅读:
    埋点功能测试
    jmeter提取A接口返回值传入B接口
    css(2)---倒角阴影 框模型
    css(1)
    node 练习
    学习过程中遇到的问题及解决方法
    node.js(5)——mysql、连接池
    node.js(4)——中间件
    node.js(3)——express
    node.js(2)
  • 原文地址:https://www.cnblogs.com/JsonZhangAA/p/5459649.html
Copyright © 2011-2022 走看看