?? stack.cpp
字號:
#include <iostream.h>
#include <stdlib.h>
#include "stack.h"
//typedef int ElementType;
void InitStack (Stack *S, int MaxSize)
{
S->base = new ElementType[MaxSize];
S->top = 0;
S->StackSize = MaxSize;
}
void DestroyStack (Stack *S)
{
delete S;
}
void ClearStack(Stack *S)
{
S->top = 0;
delete S->base;
}
bool Empty(Stack S)
{
if (S.top==0)
return true;
else
return false;
}
int StackLength(Stack S)
{
return S.top;
}
bool GetTop(Stack S,ElementType &e)
{
if (S.top == 0)
return false;
else
{
e = *(S.base+S.top-1);
return true;
}
}
bool Push(Stack *S,ElementType e)
{
if((S->top)==(S->StackSize))
return false;
else
{
*(S->base+(S->top)) = e;
(S->top)++;
return true;
}
}
bool Pop(Stack *S,ElementType &e)
{
if (S->top==0)
{
cout<<"empty"<<endl;
return false;
}
else
{
e = *((S->base)+(S->top)-1);
(S->top)--;
return true;
}
}
void Dec2Oct( int Dec)
{
/* ElementType E;
Stack *S;
S = new Stack;
InitStack (S,10);
cout<<"input the Decimal number:"<<Dec<<endl;;
while (Dec)
{
Push(S,Dec%8);
Dec = Dec/8;
}
cout<<"the octal number is:";
while (Pop(S,E))
{
cout<<E;
}*/
}
void Invert()
{
char *a;
a=new char[];
cin.getline(a,100,'\n');
ElementType E;
Stack *S;
S = new Stack;
InitStack (S,10);
E = a;
int i = 0;
int j = 0;
while (*(a+i)!='\0')
{
Push (S,E);
while (*(a+j)!=' ')
{
j++;
i++;
}
*(E+j)='\0';
E = a+j+1;
j=0;
i++;
}
Pop(S,E);
cout<<E<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -