July 微软面试100题 第十题自己的思路
来源:互联网 发布:中级会计师网络课程 编辑:程序博客网 时间:2024/05/21 08:03
用两个栈相互入栈出栈。达到输出字符的目的,代码如下:
#include <iostream.h>
#include <stdio.h>
#include <malloc.h>
//用两个栈处理字符串,通过出栈入栈输出字符串
typedef struct Stack
{
char a[256];
int top;
int base;
int size;
}*sqstack;
sqstack InitialStack()
{
sqstack s=(sqstack)malloc(sizeof(Stack));
s->base=0;
s->top=0;
s->size=0;
return s;
}
int push(sqstack s,char a)
{
if(s->size>=256)
{
cout<<"The Stack Is Full!"<<endl;
return 0;
}
s->a[s->top]=a;
(s->top)++;
(s->size)++;
return 1;
}
char Pop(sqstack s)
{
if(s->size==0)
{
cout<<"The Stack Is Empty!"<<endl;
return 0;
}
char a;
a=s->a[(s->top)-1];
(s->top)--;
(s->size)--;
return a;
}
int stackEmpty(sqstack s)
{
if(s->size==0)
return 1;
else
return 0;
}
int main()
{
cout<<"Please Enter The Sentence:"<<endl;
char s[256];
gets(s);
int i=0;
char a;
char b;
sqstack stack1,stack2;
stack1=InitialStack();
stack2=InitialStack();
while(s[i]!=0)
{
push(stack1,s[i]);
i++;
}
while(!stackEmpty(stack1))
{
do
{
a=Pop(stack1);
if(a!=' ')
push(stack2,a);
}while(a!=' '&&!stackEmpty(stack1));
while(!stackEmpty(stack2))
{
b=Pop(stack2);
cout<<b;
}
if(!stackEmpty(stack1))
cout<<" ";
}
cout<<endl;
}
- July 微软面试100题 第十题自己的思路
- July 微软面试100题 第13题
- July 微软面试100题 第18题 约瑟夫环
- 微软等数据结构+算法面试100题 by July
- July 微软面试100题 第11题 求二叉树的最大距离
- July 微软面试100题 第16题 二叉树的层次遍历
- July的微软面试100题系列尝试解答(1~5题)
- July 微软面试100题 第17题 字符串中第一个只出现一次的字符
- july:微软等公司数据结构+算法面试100题(第1-100题)首次完整亮相
- 把二元查找树转变成排序的双向链表(JULY微软面试100题系列第一题)的算法思考
- 微软等数据结构与算法面试100题第十题
- 翻转句子中单词的顺序 【微软面试100题 第十题】
- 由July师兄微软100题之第4题引发的递归程序设计心得
- 微软算法题--采自July博客
- july微软一百题系列之12
- 数据结构+算法面试100题~~~摘自CSDN,作者July
- 数据结构+算法面试100题~~~摘自CSDN,作者July
- 数据结构+算法面试100题~~~摘自CSDN,作者July
- 四分之一人生
- 转载:360上市:一个昂贵的免费故事
- 嵌入式linux中文站
- 用ajax.NET 实现无刷新投票、评论
- 开通博客
- July 微软面试100题 第十题自己的思路
- 有关代码的阅读
- String == equals StringBuffer 连接字串
- 【转】Repeater绑定泛型List
- 获取LABEL与构建InstanceList
- 开始认真学习MIPS
- Python 發送Mail
- freescale i.mx23平台上移植android2.2-froyo (mx23系列)
- PAIP.通过公共网络传递秘密信息.txt (包括语音和文字)