In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to realize a Joseph ring in C language". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how C language realizes a Joseph ring".
Realization of Joseph Ring in C language
1. Allusions:
It is said that the famous Jewish historian Josephus has the following story: after the Roman occupation of Jotapat, 39 Jews hid in a hole with Josephus and his friends. 39 Jews decided that they would rather die than be caught by their enemies, so they discussed a way to commit suicide:
Forty-one people are lined up in a circle, starting with the first person to count, and every time the third person is counted, the person must commit suicide, and then the next one will re-count until all of them commit suicide. However, Josephus and his friends didn't want to obey. Josephus asked his friend to pretend to obey. He arranged his friend and himself in the 16th and 31st places, so he escaped the death game.
Second, it is realized by cyclic linked list.
1. Joseph ring realization
SListNode* JosephCycle (sListNode* pHead, DataType x) {if (pHead = = NULL) return NULL; sListNode* cur = pHead; while (1) {DataType m = x; if (cur- > next = = cur) {return cur;} while (--m) {cur = cur- > next;} / / delete replacement cur- > data = cur- > next- > data; sListNode* del= cur- > next; cur- > next = cur- > next- > next; free (del); del=NULL;}
two。 test
Void TestJosephCycle () {sListNode* list = NULL; Push_Back (list, 1); Push_Back (list, 2); Push_Back (list, 3); Push_Back (list, 4); Push_Back (list, 5); Push_Back (list, 6); Push_Back (list, 7); Push_Back (list, 8); Push_Back (list, 9); PrintList (list); / / sListNode* cur = list While (cur- > next! = NULL) {cur = cur- > next;} cur- > next = list; sListNode* ret = JosephCycle (list, 3); cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.