文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>只使用栈操作的排序

只使用栈操作的排序

时间:2010-09-16  来源:wqfhenanxc

只使用栈操作的排序

Write a C program to sort a stack in ascending order. You should not
make any assumptions about how the stack is implemented. The following
are the only
functions that should be used to write this program:
Push | Pop | Top | IsEmpty | IsFull

解答:
 The algorithm is O(N^2) and appears below.

void sort_stack(Stack * src, Stack * dest)
{
    while (!src->IsEmpty())
   {
       Int tmp = src->Pop();
       while(!dest->IsEmpty() && dest->Top() > tmp)
       {
          src->Push(dest->Pop());
       }
       dest->Push(tmp);
   }


}


相关阅读 更多 +
排行榜 更多 +
战斗模拟比赛最新版

战斗模拟比赛最新版

冒险解谜 下载
Army Toys Town

Army Toys Town

冒险解谜 下载
AdGuard去广告大杀器下载

AdGuard去广告大杀器下载

生活实用 下载