c语言实验题数组逆序,【C语言】利用栈将数组中字符串逆序
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
#include"stdio.h"
#include"stdlib.h"
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct
{char *base;
char *top;
int stacksize;
}SqStack;
main()
{SqStack S;
char a[4];
int i;
InitStack(&S);
printf("請輸入字符:\n");
for(i=0;i<4;i++)
scanf("%c",&a[i]);
for(i=0;i<4;i++)
Push(&S,a[i]);
for(i=0;i<4;i++)
Pop(&S,&a[i]);
for(i=0;i<4;i++)
printf("%c",a[i]);
}
int InitStack(SqStack *S)
{S->base=(char *)malloc(STACK_INIT_SIZE * sizeof(char));
if(!S->base) return 0;
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return 1;
}
int Push(SqStack *S,char e)
{if(S->top-S->base>=S->stacksize)
{S->base=(char *)realloc(S->base,(S->stacksize+STACKINCREMENT) * sizeof(char));
if(!S->base) return 0;
S->top=S->base+S->stacksize;
S->stacksize+=STACKINCREMENT;
}
*S->top++=e;
return 1;
}
int Pop(SqStack *S,char *e)
{if(S->top==S->base) return 0;
*e=*--S->top;
return 1;
}
總結
以上是生活随笔為你收集整理的c语言实验题数组逆序,【C语言】利用栈将数组中字符串逆序的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 信用卡取现提前还款利息怎么算 早还早结息
- 下一篇: 银行理财的误区有什么?这几点不容错过!
