日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数据结构-joseph环

發(fā)布時(shí)間:2025/3/21 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据结构-joseph环 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

joseph環(huán)
//時(shí)間:05/07/04
//程序:張建波

//輸入 n=7?? // 3,1,7,2,4,7,4? //輸出6 7 4 1 5 3 2


#include <iostream.h>
#include "key.h"

typedef struct person
{ int pwd;? //密碼
? int num;? //人數(shù)
? struct person *next;? //指向結(jié)構(gòu)體的指針
}PERSON;
?
?

void OutPut(int *a,int n);//輸出結(jié)果
int CreatPersonList(PERSON *head);// 創(chuàng)建一張鏈表
int Fx_PersonList(PERSON *head,int n,int *a);//模擬報(bào)數(shù)


int _f4_main() //函數(shù)入口
?{

?? PERSON *head;? //定義鏈表頭

?? cout<<"joseph環(huán) 問題模擬!"<<endl;

?? head=new person; //新建PERSON,并分配內(nèi)存

?? int n=CreatPersonList(head);? // 創(chuàng)建一張鏈表,同時(shí)返回人數(shù) n

?? int *a=new int[20]; //保存輸出的結(jié)果

?? int x=Fx_PersonList(head,n,a);? //模擬報(bào)數(shù),同時(shí)返回出隊(duì)人數(shù) count
??
?? OutPut(a,x);? //輸出序列

?? InitKey();//鍵盤中斷

?? return 0;
? }


int CreatPersonList(PERSON *head){
? int n,m,i;
? PERSON *p,*q;
? cout<<"/n請輸入 n=";
? cin>>n;
? p=head;??????? //p指向表頭
?? for(i=1;i<=n;i++){? //建立鏈表
??? ? cout<<"/n請輸入第"<<i<<"的人的報(bào)數(shù)密碼m=";
??? ? cin>>m;
????? p->pwd=m;
????? p->num=i;
????? q=new person;
??? if(i==n)p->next=head; //當(dāng) i==n時(shí),循環(huán)結(jié)束把p1指向表頭
??? else
??? ??? {
??? ??? p->next=q;
??? ??? p=q;
??? ??? }

?? }
?? return n;

}


int Fx_PersonList(PERSON *head,int n,int *a){
?? PERSON *p1,*p0,*p;
?? int tm;? //臨時(shí)變量,保存上一密碼值
?? int m;? //報(bào)數(shù)密碼 m
?? int count=1; //出隊(duì)計(jì)數(shù)

??? p0=p1=head;? //使p0,p1都指向head頭

?? cout<<"/n請輸入 M 的 起始值 m=";
?? cin>>m;
?? while(count<=n-1)
???? {
??? ??? ? for(int i=1;i<m;i++)
??? ??? ??? { //把 m 重新作為報(bào)數(shù)上限值
??? ??? ??? p1=p0;
??? ??? ??? p0=p0->next;
??? ???? ??? tm=p0->pwd;
??? ??? ??? }
??? ??? m=tm;
??? ??? p=p0->next;
??? ??? a[count++]=p0->num;?? //把每次出隊(duì)的序號(hào)保存在a[x]中
??? ??? p1->next=p0->next;
??? ??? delete p0;
??? ??? p0=p;
???? }
??? a[count]=p0->num;?? //把每次出隊(duì)的序號(hào)保存在a[x]中
??? p1->next=p0->next;
??? delete p0;

??? return count;
}

void OutPut(int *a,int n)
{
? cout<<"正確的輸出序列為:";
???? for(int i=1;i<=n;i++)??? ?cout<<a[i]<<" ";
??
}

轉(zhuǎn)載于:https://www.cnblogs.com/hgndinfo/archive/2006/02/09/2713948.html

總結(jié)

以上是生活随笔為你收集整理的数据结构-joseph环的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。