Joseph Ring Problem (lead node)

Source: Internet
Author: User

  

/*
Summary: is to create a circular single-linked list, and then the loop to delete the node:
Note: 1. When the pointer variable s is not allocated dynamic memory, it is equal to another pointer that allocates memory (q) equivalent to
Point S to its memory and cannot establish a link.
2. This linked list lead node
Problems encountered: 1. In the selection of people encountered obstacles (do not know how to choose)

2. Set head node, loop (difficulty)


* * #include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
static int count;
typedef struct NODE
{
int num;
struct node *next;
}lnode,*linklist;

Linklist creat (linklist l,int N)
{
Linklist p,s,q;
int i; Count=n;
p= (linklist) malloc (sizeof (Lnode));
p->next=null;
l->next=p;
p->num=1;
S=p;
for (i=2;i<=n;i++)
{
Q= (linklist) malloc (sizeof (Lnode));
q->num=i;
s->next=q;
s=q;
}
s->next=l->next;
return l;


}

void Select (Linklist l,int m)
{
Linklist p,q,s;
int i,j,t=0;
P=l;
for (i=0;i<count;i++)//output eight values
{
for (j=1;j<m;j++)//Pointer right shift
{
p=p->next;
}
q=p->next;
printf ("%d", q->num);
p->next=q->next;//Note that the difference between assignment and link is related to next;
Free (q);//Note: After deleting node 1, start from node 5;
}

}


int main ()
{
Linklist l,s;
L= (linklist) malloc (sizeof (Lnode));
int n,m;
printf ("Please enter the number of n:\n");
scanf ("%d", &n);
Creat (L,n);
printf ("Number to figure is m:\n");
scanf ("%d", &m);
Select (L,m);

return 0;
}

Joseph Ring Problem (lead node)

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.