# 1. Delete duplicate elements from the list

Compared with the latter, the former deletes nodes and releases memory in the same way.

```void DeleteEqual(PNODE &pHead){		//Delete duplicate elements from the list
PNODE p,q,prev;
prev=p;
p=p->next;
}
while (p){
if (p->data==prev->data){
q=p;
p=p->next;
prev->next=p;
free(q);
}
else
{
prev=p;
p=p->next;
}
}
}
```

# 2. Delete elements larger than min and smaller than max in incremental ordered list

First, find two precursors, release the intermediate nodes, and re-link the list.

```void DeleteSelect(PNODE &pHead,int min,int max){		//Delete elements larger than min and smaller than max in incremental ordered list

int flag=0;
while (p->next){
if(p->next->data>min&&!flag){
minPrev=p;
flag=1;
}

if(p->next->data>=max){
maxPrev=p;
break;
}

p=p->next;
}

PNODE temp,start;
start=minPrev->next;
while(start->data!=maxPrev->data){
temp=start;
start=start->next;
free(temp);
temp=NULL;
}
minPrev->next=maxPrev->next;
free(maxPrev);
maxPrev=NULL;
}
```

## The first strategy:

```void LinkListReverse(PNODE &L){			//Inverse list with more than 2 elements
PNODE p,q,s;
p=L->next;
q=p->next;
s=q->next;
p->next=NULL;
while(s->next){
q->next=p;
p=q;
q=s;
s=s->next;
}
q->next=p;
s->next=q;
L->next=s;
}
```

## The second strategy

```void LinkListReverse2(PNODE &L){			//Inverse linked list
PNODE p,s,prev;
if (p=L->next){
prev=p;
s=p;
p=p->next;
prev->next=NULL;
}

while(p){
s=p;
p=p->next;
s->next=prev;
prev=s;
}
L->next=s;
}
```

# Complete code:

```#include<iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

typedef struct Node//node
{
int data;//Data Domain
struct Node *next;//Pointer field
}NODE, *PNODE;//NODE is equivalent to struct Student st||PNODE is equivalent to struct Node *next

PNODE InputStudent(void)
{
int len;//Number of students
NODE stu;
if(NULL == pHead)	//Determine whether memory is empty
{
printf("memory allocation failed,Procedure termination!\n");
exit(-1);
}
pTail->next = NULL;//Empty the pointer field
scanf("%d",&len);
for(int i=0; i<len; i++)
{
cin>>stu.data;

PNODE pNew = (PNODE)malloc(sizeof(NODE));	//Allocate memory for new nodes
if(NULL == pNew)	//Determine whether memory is empty
{
printf("memory allocation failed,Procedure termination!\n");
exit(-1);
}

pNew->data = stu.data;//Initialize the data domain of the node
pTail->next = pNew;//Hang the new node after the old one
pNew->next = NULL;//Clear the pointer field of the new node
pTail = pNew;//Move pTail to a new node
}
}

void OutputStudent(PNODE pHead)//Output of Student Information
{
PNODE p = pHead->next;//Define a pointer to traverse student information
printf("\n The data are as follows:\n");
while(NULL != p)
{
printf("%d ", p->data);
p = p->next;
}
}

void DeleteEqual(PNODE &pHead){		//Delete duplicate elements from the list
PNODE p,q,prev;
prev=p;
p=p->next;
}
while (p){
if (p->data==prev->data){
q=p;
p=p->next;
prev->next=p;
free(q);
}
else
{
prev=p;
p=p->next;
}
}
}

void DeleteSelect(PNODE &pHead,int min,int max){		//Delete elements larger than min and smaller than max in incremental ordered list

int flag=0;
while (p->next){
if(p->next->data>min&&!flag){
minPrev=p;
flag=1;
}

if(p->next->data>=max){
maxPrev=p;
break;
}

p=p->next;
}

PNODE temp,start;
start=minPrev->next;
while(start->data!=maxPrev->data){
temp=start;
start=start->next;
free(temp);
temp=NULL;
}
minPrev->next=maxPrev->next;
free(maxPrev);
maxPrev=NULL;
}

PNODE p,q,s;
p=L->next;
q=p->next;
s=q->next;
p->next=NULL;
while(s->next){
q->next=p;
p=q;
q=s;
s=s->next;
}
q->next=p;
s->next=q;
L->next=s;
}

PNODE p,s,prev;
if (p=L->next){
prev=p;
s=p;
p=p->next;
prev->next=NULL;
}

while(p){
s=p;
p=p->next;
s->next=prev;
prev=s;
}
L->next=s;
}

int main(){
PNODE L= InputStudent();
cout<<endl<<"The input data are as follows:";
OutputStudent(L);

//	DeleteEqual(L);
//	Cout < endl < < "after deletion:";
//	OutputStudent(L);