栈的问题!

preetyboy200 2003-08-22 09:54:54
请用C语言来编写一个你逆序输出(用栈来实现)
请写出源程序
...全文
44 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
willian2003 2003-10-06
  • 打赏
  • 举报
回复
我也想知道啊用c怎么做呢?
xiaomimiya 2003-08-23
  • 打赏
  • 举报
回复
#include<stdio.h>
main()
{
char a[20];
int i;
gets(a);
for(i=strlen(a)-1;i>=0;i--)
printf("%c",a[i]);
printf("\n");
getch();
}
preetyboy200 2003-08-23
  • 打赏
  • 举报
回复
你是用C++做的
我不懂啊
senda 2003-08-22
  • 打赏
  • 举报
回复
程序没有编译,不知通不通。
哈哈,IBM小子,他可是大师啊,要加油啊
senda 2003-08-22
  • 打赏
  • 举报
回复
#include<iostream.h>
#include<stdlib.h>

typedef int DataType;
const int MaxSize = 20;

class Stack
{
private:

//array list
DataType list[MaxSize];
int rear, front, count;

public:

//constructure
Stack(void);

//change stack methods
void Push(const DataType &item);
DataType Pop(void);
void ClearStack(void);

//access stack methods
DataType Front(void) const;
int Empty(void) const;
int Full(void) const;
};

Stack::Stack(void)
{
front = rear = count = 0;
}

void Stack::Push(const DataType &item)
{
if(count == MaxSize - 1)
{
cerr<<"stack already full"<<endl;
exit(1);
}

list[count] = item;
count++;
rear = (rear + 1) % MaxSize;
}

DataType Stack::Delete(void)
{
DataType temp;

if(count == 0)
{
cerr<<"stack is empty!"<<endl;
exit(1);
}

temp = list[count];
count--;
front = (front + 1) % MaxSize;
return temp;
}

void Stack::ClearStack(void)
{
count = 0;
}

DataType Stack::Front(void) const
{
return list[count];
}

int Stack::Empty(void) const
{
return count == 0;
}

int Stack::Full(void) const
{
return count == MaxSize - 1;
}

void main()
{
Stack S;
char string[12];

cout<<"Enter a string: ";
cin.getline(string, 12, '\n');

while(string[i] != NULL)
S.Push(string[i++]);

while(!S.Empty())
cout<<S.Pop();

cout<<endl;
}

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧