日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > Algorithm One Day One -- 約瑟夫環(丟手絹問題)

Algorithm One Day One -- 約瑟夫環(丟手絹問題)

來源:程序員人生   發布時間:2015-02-02 08:20:39 閱讀次數:2878次

算法是編程的靈魂,是編程思想的精華――――Algorithm One Day One


/******************************************************************** created:2015年1月20日 23:06:46 author: Jackery purpose: Joseph problem *********************************************************************/ #include"stdafx.h" #include<iostream> using namespace std; typedef struct _Node { int data; struct _Node*next; } node_t; typedef struct _Linklist { node_t*phead; node_t*ptail; int len; }Linklist; static node_t*GetNode(int i )//新建并初始化節點 { node_t*pNode; pNode=new node_t; if(!pNode) { cout <<"內存分配失敗" <<endl; exit(⑴); } pNode->data=i; pNode->next=NULL; return pNode; delete pNode; } void init_list(Linklist*plist)//用第1個節點初始化循環單鏈表 { node_t*p; p=GetNode(1); //printf("TheNewNodeis:%d ",p->data);//****TEST**** plist->phead=p; plist->ptail=p; p->next=plist->phead; plist->len=1; } //把其余數據添加到循環單鏈表中 static void Create_List(Linklist*plist,int n) { int i=0; node_t*pNew; for(i=2;i<=n;i++) { pNew=GetNode(i); /********TEST******** cout <<"The New Node is:" <<pNew->data << endl; ********TEST********/ plist->ptail->next=pNew; plist->ptail=pNew; pNew->next=plist->phead; plist->len++; } } //輸出鏈表內容 // void Print_List(Linklist*plist) // { // node_t*pCur=plist->phead; // do // { // cout << "The "<< pCur->data <<"person." <<endl; // pCur=pCur->next; // }while(pCur!=plist->phead); // cout << "The length of the List "<< plist->len<< endl;; // } //Joseph function implement void joseph(Linklist* plist,int m,int k) { node_t *pPre=plist->ptail; node_t *pCur=plist->phead; int i,j; cout << "出隊列的順序順次為: "<< endl; while(plist->len != 1) { i=0; j=0; while(j<k⑴) { pPre=pPre->next; j++; } while(i< m ⑴) { pPre=pPre->next; i++; } pCur=pPre->next; int temp=pCur->data; cout <<"第 " << temp << " 個人 "<< endl ; pPre->next=pCur->next; free(pCur); plist->len--; } cout <<"第 " << pPre->data << " 個人" << endl; ; cout << "The last one is:" << pPre->data<< endl; } int main(int argc, char * argv[]) { int n=0; cout <<"約瑟夫環長度為 : "<<endl;; cin >> n; int m=0; cout << "每此數到m個時,這人出列"<<endl; int k; cin >> k; cout << "從第k 個開始數" << endl; cin >>m; Linklist pList; init_list(&pList); Create_List(&pList,n); // Print_List(&pList); joseph(&pList,m,k); return 0; }



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 日韩精品成人一区二区在线观看 | av福利网站 | 亚洲精品aⅴ中文字幕乱码 九九九久久 | 日韩一区二区精品视频 | 99久热| a在线免费 | 精品成人一区二区 | 麻豆国产在线 | 国产精品视频一二区 | 91av视屏 | 欧美在线一区二区三区四区 | 国产99在线 | 欧美 | 综合网亚洲| 国产精品美女久久 | 日日日操操操 | 久热国产精品 | 激情婷婷综合 | 精品国产传媒 | 国产精品一区二区在线看 | 亚洲 欧美 日韩 在线 | 免费在线黄色网址 | 国产在线专区 | 久久免费视频网站 | 日韩福利一区二区 | 欧美福利在线观看 | 精品视频网站 | 天天操,狠狠操 | 岛国片在线免费观看 | 人妖被c到高潮欧美gay | 欧洲成人精品 | 日本一区二区免费在线 | 男女午夜视频在线观看 | 欧美 日韩 亚洲 国产 | 亚洲午夜久久久 | 黄色一级片视频播放 | 久久久久网站 | 久久综合av | 国产激情在线观看 | 黄色网址av | 一级特黄免费 | 久久中文字幕一区二区 |