The questions are roughly as follows:
Implement the insert/delete operation of the circular linked list
Insert the number from 1 to, and then delete them in sequence by Step 2. The values are 3, 5, 7, 9, 13, 15, 17... until the linked list is empty and the number of deleted items is printed.
I didn't make it completely at the time. Now it has been implemented. It is not the best way to paste the code below. You are welcome to discuss it.
# Include <stdio. h> <br/> # include <stdlib. h> <br/> # include <string. h> <br/> # include <windows. h> </P> <p> # define quick_delete </P> <p> typedef struct node <br/>{< br/> int data; <br/> struct node * Next; <br/>} nodet; </P> <p> void output (nodet * tail ); <br/> nodet * insert (nodet ** tail, int data); <br/> nodet * Delete (nodet ** tail, int data ); // return the front PTR <br/> nodet * quickdelete (nodet * front, nodet * Curren T); </P> <p> nodet * tail = NULL; </P> <p> int main () <br/>{< br/> long begin, end; <br/> # ifdef quick_delete <br/> nodet * front; <br/> # endif <br/> nodet * head, * current; <br/> int I, step = 2; </P> <p> for (I = 1; I <= 100; I ++) <br/>{< br/> insert (& tail, I); <br/>}</P> <p> output (tail ); </P> <p> printf ("---------------------------------------------------------------/N"); </P> <p> head = tail-> next; <br/> current = head; <Br/> # ifdef quick_delete <br/> front = current; <br/> # endif </P> <p> begin = gettickcount (); </P> <p> while (current! = NULL) <br/>{< br/> while (step! = 0) <br/>{< br/> # ifdef quick_delete <br/> front = current; <br/> # endif <br/> current = Current-> next; <br/> step --; <br/>}< br/> step = 2; </P> <p> // Delete <br/> printf ("% d", current-> data ); </P> <p> # ifdef quick_delete <br/> current = quickdelete (front, current); <br/> # else <br/> current = Delete (& tail, current-> data); <br/> # endif <br/>}</P> <p> end = gettickcount (); </P> <p> printf ("/N"); </P> <p> printf ("End-be Gin = % d MS! /N ", end-begin); </P> <p> system (" pause "); </P> <p> return 0; <br/>}</P> <p> void output (nodet * tail) <br/> {<br/> nodet * head = NULL, * Current = NULL; </P> <p> If (tail = NULL) <br/> return; </P> <p> head = tail-> next; <br/> current = head; </P> <p> while (current! = Tail) <br/>{< br/> printf ("% d", current-> data); <br/> current = Current-> next; <br/>}</P> <p> while (current! = Head-> next) <br/>{< br/> printf ("% d", current-> data); <br/> current = Current-> next; <br/>}< br/> printf ("/N"); <br/>}</P> <p> nodet * insert (nodet ** tail, int data) <br/>{< br/> nodet * newp = NULL; </P> <p> If (tail = NULL) <br/> return NULL; </P> <p> newp = (nodet *) malloc (sizeof (nodet); <br/> If (newp = NULL) <br/> return NULL; <br/> newp-> DATA = data; <br/> newp-> next = NULL; </P> <p> If (* tail = NULL) <br/> {<B R/> * tail = newp; <br/> newp-> next = newp; <br/>}< br/> else <br/> {<br/> newp-> next = (* tail)-> next; <br/> (* tail) -> next = newp; <br/>}< br/> * tail = (* tail)-> next; </P> <p> return (* tail) -> next; <br/>}</P> <p> nodet * Delete (nodet ** tail, int data) <br/>{< br/> int find = 0; <br/> nodet * head, * Current, * front; </P> <p> If (tail = NULL | * tail = NULL) <br/> return NULL; </P> <p> head = (* tail)-> next; <br/> current = Head; <br/> front = * tail; </P> <p> while (current! = * Tail) <br/>{< br/> If (current-> DATA = data) <br/>{< br/> Find = 1; <br/> break; <br/>}< br/> else <br/>{< br/> front = current; <br/> current = Current-> next; <br/>}< br/> If (* tail)-> DATA = data) <br/> Find = 1; </P> <p> If (find! = 1) <br/> return NULL; </P> <p> If (Head = * tail) <br/>{< br/> free (* tail ); <br/> * tail = front = current = NULL; <br/>}< br/> else <br/>{< br/> If (current = * tail) <br/>{< br/> front-> next = Current-> next; <br/> * tail = front; <br/> free (current ); <br/>}< br/> else <br/>{< br/> front-> next = Current-> next; <br/> free (current ); <br/>}</P> <p> return front; <br/>}</P> <p> nodet * quickdelete (nodet * front, nodet * Current) <br/>{< br/> If (front = Current & current = tail) <br/>{< br/> free (current ); <br/> return NULL; <br/>}< br/> else <br/>{< br/> If (current = tail) <br/>{< br/> front-> next = Current-> next; <br/> tail = front; <br/> free (current ); <br/>}< br/> else <br/>{< br/> front-> next = Current-> next; <br/> free (current ); <br/>}< br/> return front; <br/>}< br/>