برگزیده های پرشین تولز

circular linklist output

srad

کاربر تازه وارد
تاریخ عضویت
8 مارس 2007
نوشته‌ها
2
لایک‌ها
0
here is a code about a circularlinklist,which its nodes contain a number between 1 to 2048(first node contains 1 and the lastnode contains 2048) and pointer P that refers to the last node...what does this code do?
while(p->next!=p){
p->next=p->next->next;
p=p->next;
}
cout<< p->info;​
 

Arash_j13

Registered User
تاریخ عضویت
18 فوریه 2005
نوشته‌ها
778
لایک‌ها
2
محل سکونت
مشهد
Josephus problem
The Josephus problem (or Josephus permutation) is a theoretical problem occurring in computer science and mathematics.

There are n people standing in a circle waiting to be executed. After the first man is executed, k − 1 people are skipped and the k-th man is executed. Then again, k − 1 people are skipped and the k-th man is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last man remains, who is given freedom.

The task is to choose the place in the initial circle so that you survive (are the last one remaining), given n and k.

History
The problem is named after Flavius Josephus, a Jewish historian living in the 1st century. As the legend goes, he and his 40 comrade soldiers were trapped in a cave, surrounded by Romans. They chose suicide over capture and decided that they will form a circle and start killing themselves using a step of three. As Josephus did not want to die, he was able to find the safe place, and stayed alive with his comrade, later joining the Romans who captured them.

For more information visit Josephus problem.

 
بالا