最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
偶做的简单行编辑程序
时间:2022-07-02 10:58:41 编辑:袖梨 来源:一聚教程网
这是我的行编辑程序,各位指点指.
#include
#include
#define STACK_INIT_SIZE 100
#define MAXSIZE 50
#define INCREMENT 10
#define OVERFLOW -2
#define ERROR -1
#define OK 0
typedef struct
{
int *base;
int *top;
int StackSize;
}SqStack,*PStack;
void InitStack(PStack S);
void DestroyStack(PStack S);
void ClearStack(PStack S);
int GetTop(PStack S,int *e);
void Push(PStack S,int e);
int Pop(PStack S);
void InitStack(PStack S)
{
if(!(S->base = (int *)malloc(STACK_INIT_SIZE *sizeof(int))))
exit(OVERFLOW);
S->top = S->base;
S->StackSize = STACK_INIT_SIZE;
return;
}
void DestroyStack(PStack S)
{
free(S->base);
S->top = S->base;
return;
}
void ClearStack(PStack S)
{
S->top = S->base;
return;
}
int GetTop(PStack S,int *e)
{
if(S->top == S->base)
return ERROR;
*e = *(S->top - 1);
return OK;
}
void Push(PStack S,int e)
{
if(S->top - S->base >=S->StackSize)
{
S->base = (int *)realloc(S->base,(STACK_INIT_SIZE + INCREMENT) *sizeof(int));
if(!S->base)
exit(OVERFLOW);
S->top = S->base + S->StackSize ;
S->StackSize = S->StackSize + INCREMENT;
}
*S->top ++ = e;
return;
}
int Pop(PStack S)
{
if(S->top - S->base ==0)
return ERROR;
S->top --;
return OK;
}
int main()
{
SqStack S;
char ch;
FILE *fp;
char Array[MAXSIZE];
int *p;
int i ;
InitStack(&S);
printf("please enter the context:n");
ch = getchar();
while(ch != '!')
{
while(ch != '!' && ch != 'n')
{<
相关文章
- 《原神》5.2卡池抽取建议 11-14
- 《原神》5.2版本新怪物介绍 11-14
- 《原神》希诺宁增伤触发方法 11-14
- 《原神》循音觅奇活动入口 11-14
- 《原神》循音觅奇兑换码获取方法 11-14
- 《原神》花羽会活动飞行技巧介绍 11-14