Joseph ring

Source: Internet
Author: User
Tags define null

 
Module Division
(1) the single-cycle linked list of the leading node abstracts the data type sclinlist, including the basic operation functions: initialize the operation function, insert a node operation function, and delete several node operation functions, take a node data operation function and determine whether the table is a non-empty operation function.
(2) void sclldeleteafter (sclnode * p) is used to delete the next node of the node indicated by p in the single-cycle linked list of the lead node.
(3) void jesephring (sclnode * head, int m), which is a single-cycle linked list head of the leading node,
Use m as the upper limit of the initial report to meet the problem requirements.
(4) void main (), the main function, which provides the test data value, establishes the lead node single-cycle linked list of the test data value, and calls the jesering () function to implement the problem.
# Include <stdio. h>
# Include <stdlib. h>
# Define null 0
// The data type datatype is defined as follows:
Typedef struct
{
Int number;
Int cipher;
} Datatype;
 

// The struct of the single-cycle linked list node of the leading node is defined as follows:
Typedef struct node
{
Datatype data;
Struct node * next;
} Sclnode;
 

// Initialization
Void scllinitiate (sclnode ** head)
{If (* head = (sclnode *) malloc (sizeof (sclnode) = null) exit (1 );
(* Head)-> next = * head;
 }
 

// Insert a node
Int scllinsert (sclnode * head, int I, datatype x)
 {
Sclnode * p, * q;
Int j;
P = head-> next; j = 1;
While (p! = Head & j <i-1)
{P = p-> next; j ++;
  }
If (j! = I-1 & I! = 1)
{Printf ("input parameter error! ");
Return 0;
  }
If (q = (sclnode *) malloc (sizeof (sclnode) = null) exit (1 );
Q-> data = x;
Q-> next = p-> next;
P-> next = q;
Return 1;
  }
 

// Delete a node
Int sclldelete (sclnode * head, int I, datatype * x)
  {
Sclnode * p, * q;
Int j;
P = head; j = 0;
While (p-> next! = Head & j <i-1)
{P = p-> next; j ++ ;}
If (j! = I-1)
{Printf ("delete parameter error! ");
Return 0;
    }
Q = p-> next;
P-> next = p-> next;
* X = q-> data;
Free (q );
Return 1;
    }
 

// Obtain the element value of a node data
Int scllget (sclnode * head, int I, datatype * x)
  {
Sclnode * p;
Int j;
P = head; j = 0;
& N

<

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.