Data structure of the Joseph Problem (circular link list) (c + + version)

Source: Internet
Author: User

#include <iostream>
#include <stdlib.h>
using namespace Std;
typedef char ELEMTYPE;
typedef struct lnode{
Elemtype data; Data fields
struct Lnode *next; Pointer field
}lnode, *slink;

void Initlist (Slink &l) {
Slink p, R;
int N, J;
cout << "Please enter the number of single-linked list elements:";
CIN >> N;
Creates an empty list of leading nodes, L is a pointer to the head node (head pointer)
L = (slink) malloc (sizeof (Lnode));
R = L;
if (! L) exit (0); Storage space allocation failed
cout << "Please enter the elements of the single linked list:";
for (j = 0; J < N; j + +)
{
p = (slink) malloc (sizeof (Lnode)); To generate a new node
CIN >> p->data; INPUT element value
R->next = p; r = P; Insert to table header
}
R->next = NULL;
}//initlist

int main ()
{
Slink B, D, L, p, Q, RB, RD, RL;
Initlist (L);
B = new Lnode; B->next = B; Create an empty loop linked list holding letters
D = new Lnode; D->next = D; Create an empty loop linked list to hold numbers
RB = B; rd = D; RL = L;
p = L; Q = p->next;
while (q)
{
if ((' A ' <= q->data) && (q->data <= ' Z ') | | (' A ' <= q->data) && (q->data <= ' z '))
{
P->next = q->next; B->next = q; Q->next = B; B = q; Tail interpolation method
}
else if ((' 0 ' <= q->data) && (q->data <= ' 9 '))
{
P->next = q->next; D->next = q; Q->next = D; D = q;
}
else p = q;
Q = p->next;
}
P->next = L; Constructs the linked list L as a circular linked list, storing other characters
while (rb->next! = B)
{
RB = rb->next;
cout << rb->data << ";
}
cout << b->data << Endl;
while (rd->next! = D)
{
RD = rd->next;
cout << rd->data << ";
}
cout << D->data <<endl;
while (rl->next! = L)
{
RL = rl->next;
cout << rl->data << ";
}
cout << Endl;
return 0;
}

Data structure of the Joseph Problem (circular link list) (c + + version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.