多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

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

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

來源:程序員人生   發(fā)布時間:2015-02-02 08:20:39 閱讀次數(shù):2872次

算法是編程的靈魂,是編程思想的精華――――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 )//新建并初始化節(jié)點 { node_t*pNode; pNode=new node_t; if(!pNode) { cout <<"內(nèi)存分配失敗" <<endl; exit(⑴); } pNode->data=i; pNode->next=NULL; return pNode; delete pNode; } void init_list(Linklist*plist)//用第1個節(jié)點初始化循環(huán)單鏈表 { 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; } //把其余數(shù)據(jù)添加到循環(huán)單鏈表中 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++; } } //輸出鏈表內(nèi)容 // 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 <<"約瑟夫環(huán)長度為 : "<<endl;; cin >> n; int m=0; cout << "每此數(shù)到m個時,這人出列"<<endl; int k; cin >> k; cout << "從第k 個開始數(shù)" << endl; cin >>m; Linklist pList; init_list(&pList); Create_List(&pList,n); // Print_List(&pList); joseph(&pList,m,k); return 0; }



生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲精品一区二区三区中文字幕 | 亚洲欧洲在线观看 | 欧美天堂久久 | 最近中文字幕在线观看 | 欧美大片一级毛片 | www在线观看免费视频 | 免费观看成人www精品视频在线 | 日本不卡在线播放 | 伊人网视频在线观看 | 最近最新免费中文字幕一 | 中文字幕2022永久在线 | 亚洲精品国产精品国自产观看 | 亚洲国产精品久久久久久网站 | 国产欧美中文字幕 | 日韩精品中文字幕久久 | 自拍偷拍欧美 | 国产a不卡片精品免费观看 国产a国产片色老头 | 欧美最新的精品videoss | 亚洲一区网站 | 欧美一区二区三区综合色视频 | 国产亚洲人成网站观看 | 成人自拍偷拍 | 欧美乱人伦中文在线观看不卡 | 日韩男人的天堂 | 国产亚洲综合一区二区在线 | 国产精品一区二区三区四区五区 | 国产成人精品视频在放 | 日韩 欧美 国产 亚洲 中文 | 亚洲第一色区 | 久草综合网 | 国产大学生露脸激情 | 伊人久久五月天综合网 | 免费爱爱片 | 久久最新精品 | 日本一区二区三区四区不卡 | 国产精品亚洲第一区在线28石 | 亚洲国产精久久久久久久 | 亚色网址 | 亚洲成av人片在线观看 | 最近中文版字幕在线观看 | 最新色网址 |