魔术师发牌问题C++实现

 #include”CirList.h”

#include<iostream>

using namespace std;

int main()

{

 CirList<int>poker;

 for(int i=0;i<13;i++)

 {//创建循环链表,存储13张牌

  poker.AddTail(0);

 

 }

 poker.SetBegin();

 poker.GetNextNode();

 for(int i=1;i<14;i++)

 {

  poker.SetData(i);

  for(int j=0;j<=i;j++)

  {

   poker.GetNextNode();//寻找插入位置

   if(poker.GetCur()->GetData()!=0)

   {//当前位置已有牌,顺序查找下一个位置

    j–;

   }

   if(j==13)

    break;

  }

 }

 poker.SetBegin();

 poker.GetNextNode();

 for(int i=0;i<13;i++)

 {

  cout<<poker.GetCur()->GetData()<<“*”;

  poker.GetNextNode();

 }
 cout<<endl;
 return 0;

}

 参见:http://www.oschina.net/code/snippet_181847_9173

    原文作者:魔术师发牌问题
    原文地址: https://blog.csdn.net/jessierzlz/article/details/7332226
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞