#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)