熟用经典函数可让问题得到简化。。特别是正式需要用得时候能省下很多事情。

比如下面的例题:在执行栈和队列的操作时,,我们需要通过不同的方式,

好比链表重新建立往往浪费了时间——无效。。。


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <queue>
usingnamespacestd;
queue<int> q;
intmain()
{
intn,t;
scanf( "%d", &n );
for( inti = 0 ; i < n ; i++ )
q.push(i+1);
while( !q.empty())
{
t=q.front();
q.pop();
q.push(q.front());
q.pop();
}
printf("%d",t);
puts("");
//system("pause");
return0;
}
本以为这样可以解决杀人环的问题,但是Compile Error将中间改成如下:
for( inti = 0 ; i < n ; i++ )
q.push(i+1);
while( !q.empty())
{
       printf( "%d" , (q.front())'
q.pop();
q.push(q.front());
q.pop();
}
    样例输入:3
    样例输出:1 3 2
    样例输入:7
    样例输出:1 3 5 7 4 2 6