Joseph Problem Linked List Method, Joseph Problem Linked List

Updated on technology 2024-06-07
3 answers
  1. Anonymous users2024-02-11

    The above program is not written in a linked list. It can be written with a linked list.

    for(k=i;k>min;k--) When the person is removed, the person behind them moves forward in turn.

    p[k]=p[k-1];

    Anyway, it's better to use a linked list, and the readability is stronger! This is best achieved with a linked list.

  2. Anonymous users2024-02-10

    #include

    #include

    #include

    using namespace std;

    #define ok 1

    #define error 0

    #define maxsize 10

    typedef int status;

    typedef int elemtype;

    typedef struct circularlistelemtype data;

    struct circularlist *next;

    circularlist,*linklist;

    Establish a single-cycle linked list of headless nodes.

    if(n<1) return error;

    l=(linklist)malloc(sizeof(circularlist));

    l->data=1;

    if(n==1)

    int i;

    linklist p,q;

    for(i=2;i<=n;i++)

    p=(linklist)malloc(sizeof(circularlist))

    p->data=i;

    if(i==2)

    else p->next=l;

    return ok;

    Delete the next node of l.

    linklist p=l->next;

    if(p==l) return error;

    l->next=p->next;

    free(p);

    return ok; }

    void josephus(int n,int k,int m) n is the total number of people, k is the first person to start the number, and m is the number shouted by the person who is out of the queue.

    linklist l;

    init_list(l,n);

    for(int i=1;inext;

    int flag=1;

    while(flag)

    for(int i=1;inext;

    flag=delete_list(l);

    l=l->next;

    cout<<"the end:"n>>k>>m)josephus(n,k,m);

    return 0;}

  3. Anonymous users2024-02-09

    This is a very interesting linked list program.

    Linked lists must be implemented by hand to be remembered. That's why I won't send you the program source**. To give you an idea. You can try to do it yourself, then send it to me, and I'll help you change it.

    First, make a circular list of 30 nodes.

    Each node needs to have a few pieces of data, its own numbered ID, whether it has been thrown into the sea deadorlive, the pointer of the next node.

    Then you start with the first node, and every 15 nodes in the cycle, you set the "whether it has been thrown into the sea" of this node to throw it in.

    Of course, when you cycle, you must only cycle without being thrown into the sea.

    After 15 cycles, it's all right.

    Then record the numbers of all dead nodes in this circular linked list, which is the position of the non-believer.

    Hope it helps.

    It may seem like a lot of work to achieve at first, but there has to be such a painful process so that you can go better than others.

    If you still only want to find a source, then you can ignore what I typed for you. If you write a program, send it to me.

Related questions
3 answers2024-06-07

I wrote it myself and solved it directly with a one-dimensional array. >>>More

3 answers2024-06-07

Heada and headb are both singly linked lists with leading nodes. In this algorithm, we delete the common elements from the ith element in the heada linked list, and then insert the single-linked list heada before the jth element of the headb. >>>More

5 answers2024-06-07

#include

#include >>>More

7 answers2024-06-07

The maintenance cost is very high:

Traditional centralized databases only need to be written once, while blockchains need to be written thousands of times; The traditional centralized database only needs to verify the data once, while the blockchain needs to perform thousands of tests on the data; Traditional centralized databases only need to transfer data once to store it, while blockchains need to transfer data thousands of times. >>>More

9 answers2024-06-07

To be honest, you're really tired, I can really imagine how tired that is, there's a situation around me where I always say that friend of mine is too! In the end, he let go, because he was too tired, and he said that if there was no understanding between the two of them, even if they were still in love, and they were so tired of love, it would be better to give up, maybe it would be the best outcome! Giving up is also a beauty! >>>More