本文整理汇总了C++中Stack::Empty方法的典型用法代码示例。如果您正苦于以下问题:C++ Stack::Empty方法的具体用法?C++ Stack::Empty怎么用?C++ Stack::Empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack::Empty方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Commands
//Project Properties -> Configuration Properties -> Linker (General) -> Enable Incremental Linking -> "No (/INCREMENTAL:NO)"
void Commands(char *com)//2аяПроверка - построить цепочку команд.
{
int n;
n=strlen(com);
int k=1;
//Вводится строка чётной длины!
for(int i=0; i<n ;)
{
{
if (com[i] && com[i]==k)
{
st.Push(k); st.Pop(); cout<<"s"<<"x"; i++; k++;
}
else if (i<n) break;}
}
{
if (i<n && com[i]!=k)
{
st.Push(k); k++; cout<<"S";
}
}
if (st.Empty()==false)
{
if (st.Top()==com[i])
{
st.Pop(); i++; k++; cout<<"X";
}
}
}
示例2: Preorder_Traversal
void Preorder_Traversal(TreeNode Root)
{
if (Root == NULL)
{
return ;
}
// use Stack ADT to store TreeNode
Stack S;
S = Stack_Initial(S);
TreeNode Temp = Root;
while(Temp != NULL || !S.Empty())
{
while (Temp != NULL)
{ // Firstly, we deal with LeftChild
visit(Temp);
push(S, Temp);
Temp = Temp->LeftChild;
}
if(!Empty(S))
{ // traversal the previous TreeNode's RightChild
Temp = pop(S);
Temp = Temp->RightChild;
}
}
}
开发者ID:FreAkPoint,项目名称:All-about-data-structure-and-algorithmn,代码行数:26,代码来源:Preorder+Traversal_non-recursion.cpp
示例3: Test
void Test()
{
Stack<int> st;
st.Push(1);
st.Push(2);
st.Push(3);
st.Push(4);
cout<<st.Top()<<endl;
cout<<st.Size()<<endl;
cout<<st.Empty()<<endl;
}
示例4: ProverkaPoSx
void ProverkaPoSx(char *sx)//1аяПроверка - можно ли извлечь числа по заданному коду.
{
int n=strlen(sx), k=1, l=0;
for(int i=0; i<n; i++)
{
if (sx[i]=='s') st.Push(k);
else
{
if (st.Empty()==false) cout<<st.Pop()<<" ";
else {cout<<"..Error"; break;}
}
}
}
示例5: main
int main(int argc, char ** argv)
{
Stack<string> strs;
for (int i = 1; i < argc; ++i)
{
strs.Push(argv[i]);
}
while (strs.Empty() == false)
{
string name;
strs.Pop(name);
cout << name << endl;
}
return 0;
}
示例6: test
void test()
{
Stack<int> s;
for(size_t i = 1;i <= 5;i++)
{
s.Push(i);
}
cout<<"size = "<<s.Size()<<endl;
cout<<"capacity = "<<s.Capacity()<<endl;
while(!s.Empty())
{
cout<<s.Top()<<" ";
s.Pop();
}
cout<<endl;
cout<<"size = "<<s.Size()<<endl;
cout<<"capacity = "<<s.Capacity()<<endl;
}
示例7: TestMaze
void TestMaze()
{
int n = 10;
int** ppMaze = CreateMaze(n);
Pos entry = InitMaze(ppMaze, n);
PrintMaze(ppMaze, n);
Stack<Pos> path;
Maze(ppMaze, n, entry, path);
PrintMaze(ppMaze, n);
cout<<"Path:";
while (!path.Empty())
{
const Pos& pos = path.Top();
cout<<"("<<pos.row<<","<<pos.col<<")"<<"<-";
path.Pop();
}
cout<<"Entry"<<endl;
}
示例8: ProverkaPoChislam
void ProverkaPoChislam(char *chislo)//Проверка - можно ли извлечь заданные числа в заданном порядке. Происходит процесс извлечения.
{
int n=strlen(chislo), k=0, l=0;
for(int i=0; i<n; i++)
{
st.Push(k);
{if (st.Top()==chislo[i])
{
while (st.Top()==chislo[i])
{
cout<<st.Pop()<<" ";
i++;
}
i--;
}
}
k++;
}
if (st.Empty()==true) cout<<"Verno!";
else cout<<"NO!";
}
示例9: CorrectBr
bool CorrectBr(Stack& stack, char* str)
{
if (!str)
{
return false;
}
for ( UI i = 0; i < strlen(str); ++i )
{
if ( ( str[i] == ')' ) && ( stack.Top() == '(' ) )
{
stack.PopBack();
}
else if ( ( str[i] == ']' ) && ( stack.Top() == '[' ) )
{
stack.PopBack();
}
else if ( ( str[i] == '}' ) && ( stack.Top() == '{' ) )
{
stack.PopBack();
}
else if ( ( str[i] == ')' ) || ( str[i] == '(' )
|| ( str[i] == ']' ) || ( str[i] == '[' )
|| ( str[i] == '}' ) || ( str[i] == '{' ) )
{
stack.PushBack( str[i] );
}
}
if ( stack.Empty() )
{
return true;
}
else
{
return false;
}
}
示例10: while
FixTraverseMaze(Map &map, Point ptStart)
// Fixed Order(fix)-uses a fixed order in how it tries the four
// neighboring direction. North, East, South, West is the order of
// priority.
{
char step=CURRENT,count;
Stack stack;
int WrongStep=0,length;
char ok;
Point point,x,direction,tryd;
stack.Push(ptStart);
while (!stack.Empty()) {
stack.Pop(point);
if (map.GetPoint(point)==GOAL) {
map.SetPoint(point,step);
length=int(step-CURRENT+1);
cout<<"\nPath was found of length "<<length<<" with ";
cout<<WrongStep<<" wrong points visited.";
cout<<"\n(Total of "<<2*WrongStep+length<<" moves, ";
printf("algorythm efficiency: %.2f)\n",
(.0+length)/(2*WrongStep+length));
map.Print();
return(0);
}
map.SetPoint(point,step++);
stack.Push(point);
ok=0;
x.row=point.row;
x.col=point.col-1;
if (map.GetPoint(x)==FREE || map.GetPoint(x)==GOAL)
{
stack.Push(x);
ok=1;
}
x.row=point.row+1;
x.col=point.col;
if (map.GetPoint(x)==FREE || map.GetPoint(x)==GOAL)
{
stack.Push(x);
ok=1;
}
x.row=point.row;
x.col=point.col+1;
if (map.GetPoint(x)==FREE || map.GetPoint(x)==GOAL)
{
stack.Push(x);
ok=1;
}
x.row=point.row-1;
x.col=point.col;
if (map.GetPoint(x)==FREE || map.GetPoint(x)==GOAL)
{
stack.Push(x);
ok=1;
}
if (!ok)
{
ok=0;
do {
if (stack.Pop(point)==-1) return(-1);
if (map.GetPoint(point)>=CURRENT)
{
map.SetPoint(point,DEADEND);
step--;
WrongStep++;
} else
{
stack.Push(point);
ok=1;
}
} while (ok==0);
}
}
cout<<"\n Could not find the Goal.\n";
map.Print();
return(0);
}
示例11: Update
void Update(clock_t &tLast, short &charIndex, bool &newWord, char(&command)[MAX_CHARATERS_PER_LINE])
{
command[charIndex] = GetCharacter(newWord); //escuchamos la entrada de datos con un timeout para poder dedicar tiempo a los calculos posteriores
//verificamos que tenemos caracter leido o nueva palabra empezada
if (command[charIndex] != NULL || newWord != 0)
{
if (newWord == 0) { newWord = 1; } //ponemos a true el boleano de palabra
//cuando pulse enter el jugador, almacenamos la palabra en el stack y reseteamos el indice de nuestra palabra asi como el boleano
//en caso contrario aumentamos el indice para obtener una nueva letra
if (command[charIndex] == '\n')
{
command[charIndex] = 0;
if (charIndex > 0) //si tan solo pulsa enter no necesitamos almacenarlo en la pila
{
newWord = 0;
stackCommands.Push((std::string) command);
command[0] = 0;
}
else
{
Prompt();
}
charIndex = 0;
}
else
{
++charIndex;
}
}
//tratamiento acciones o comandos
//Si la pila no esta vacia y el delay se cumple ejecutamos una nueva instruccion
if (!stackCommands.Empty() && (clock() - tLast) > DELAY_BETWEEN_COMMANDS)
{
//La palabra reservada para ejecutar 'salir del juego' es especial ya que requiere de verificación.
if (LEAVE == Upcase(stackCommands.Consult()))
{
char a[MAX_CHARATERS_PER_LINE]; //para no obtener datos de la pila definios una nueva variable
a[0] = 0;
do //para salir hay que verificar antes
{
printf(LEAVE_Q);
scanf_s("%s", a, _countof(a));
} while (!Compare(YES, Upcase(a)) && !Compare(NO, Upcase(a)));
if (Compare(YES, Upcase(a))) gameState = endLoop;
else
{
Prompt();
stackCommands.Pop();
}
}
else
ShowCommands();
tLast = clock();
}
}
示例12: Maze
bool Maze(int** ppMaze, int n, const Pos& entry, Stack<Pos>& path)
{
assert(entry.col < n && entry.row < n);
Pos cur = entry;
ppMaze[cur.row][cur.col] = 2;
path.Push(cur);
while (!path.Empty())
{
Pos next = path.Top();
//
// 出口在最后一行
//
if (next.row == n-1)
{
return true;
}
// 上
next.row -= 1;
if (CheckIsAccess(ppMaze, n, next))
{
ppMaze[next.row][next.col] = 2;
path.Push(next);
continue;
}
// 右
next = path.Top();
next.col += 1;
if (CheckIsAccess(ppMaze, n, next))
{
ppMaze[next.row][next.col] = 2;
path.Push(next);
continue;
}
// 下
next = path.Top();
next.row += 1;
if (CheckIsAccess(ppMaze, n, next))
{
ppMaze[next.row][next.col] = 2;
path.Push(next);
continue;
}
// 左
next = path.Top();
next.col -= 1;
if (CheckIsAccess(ppMaze, n, next))
{
ppMaze[next.row][next.col] = 2;
path.Push(next);
continue;
}
Pos tmp = path.Top();
ppMaze[tmp.row][tmp.col] = 3;
path.Pop();
}
return false;
}