Home > Back-end >  Increasing data structure - about to delete a sequence of eligible elements, half program is running
Increasing data structure - about to delete a sequence of eligible elements, half program is running

Time:12-22

This is the topic request: the elements in the known linear table orderly arrangement by value increases, and the singly linked list storage structure, try to write an efficient algorithm to delete all the values in the table is greater than the mink and less than maxk element (if there are elements in the table) and release the delete node space
 # include & lt; stdio.h> 
#include

Typedef struct Lnode//define singly linked list storage structure
{
The int data;
Struct Lnode * next;
} Lnode * linklist;

Void CreatList (linklist L, int num [])//to create a list
{
(L)=(linklist) malloc (sizeof (Lnode));//set up leading the singly linked list of nodes
if(! L) exit (1);
(L) - & gt; Next=NULL;

int i=0;
Linklist p, q=L;

While (num [I]!=1) terminated//data for 1
{
P=(Lnode *) malloc (sizeof (Lnode));
p-> data=https://bbs.csdn.net/topics/num [I];
Q - & gt; Next=p;
p-> Next=NULL;
Q=p;
i++;
}
}

Void chushu linklist (L)
{
Linklist r=L;
R=r - & gt; Next;
while(r!=NULL)
{
Printf (" % d ", r - & gt; The data);
R=r - & gt; Next;
}
}
Int ListDelete_L (linklist L, int mink, int maxk)//delete meet the condition node
{
Linklist p, q;
P=L - & gt; Next; Q=L;
if(! P)
{
Printf (" ERROR! The list is empty!" );
exit(0);
}
while(p!=NULL)
{
If ((p - & gt; Data) & gt; Mink& & p-> Data{
Q - & gt; Next=p - & gt; Next;
Free (p);
P=q - & gt; Next;
}
The else
{
Q=p;
P=p - & gt; Next;
break;
}

}
return 1;
}

Int main ()
{
Int num [12]={0,2,3,6,13,21,33,37,45,66,99, 1};
int i;
Printf (" the original sequence: ");
for(i=0; i<11. I++)
Printf (" % d ", num [I]);
Int mink=0, maxk=0;
Printf (" \ n please enter remove elements lower mink: \ n ");
The scanf (" % d ", & amp; Mink);
Printf (" please enter remove upper bound element maxk: \ n ");
The scanf (" % d ", & amp; Maxk);
Linklist L;
CreatList (L, num);
ListDelete_L (L, mink, maxk);
Linklist p=L;
P=p - & gt; Next;
Printf (" now the sequence: ");
while(p!=NULL)
{
Printf (" % d ", p - & gt; The data);
P=p - & gt; Next;
}
}



This is to run a screenshot, I use the output mode and seemed to delete function is a little problem,
To not bottom go to, but I don't know what is wrong, is logically?? Or grammatical??
Pray god guide!!!!! You thank you thank you!!!!!!!!

CodePudding user response:

 # include & lt; stdio.h> 
#include

Typedef struct Lnode//define singly linked list storage structure
{
The int data;
Struct Lnode * next;
} Lnode * linklist;

Void CreatList (linklist * L, int num [])//to create a list
{
(* L)=(linklist) malloc (sizeof (Lnode));//set up leading the singly linked list of nodes
if(!
(* L).exit(1);
(* L) - & gt; Next=NULL;

int i=0;
Linklist p, q=* L;

While (num [I]!=1) terminated//data for 1
{
P=(Lnode *) malloc (sizeof (Lnode));
p-> data=https://bbs.csdn.net/topics/num [I];
Q - & gt; Next=p;
p-> Next=NULL;
Q=p;
i++;
}
}

Void chushu linklist (L)
{
Linklist r=L;
R=r - & gt; Next;
while(r!=NULL)
{
Printf (" % d ", r - & gt; The data);
R=r - & gt; Next;
}
}
Int ListDelete_L (linklist L, int mink, int maxk)//delete meet the condition node
{
Linklist p, q;
P=L - & gt; Next;
Q=L;
if(! P) {
Printf (" ERROR! The list is empty!" );
exit(0);
}
If # 1
While (p) {
If (p - & gt; The data & gt; Mink & amp; & p-> The data & lt; Maxk) {
Q - & gt; Next=p - & gt; Next;
Free (p);
P=q - & gt; Next;

} else {
Q=p;
P=p - & gt; Next;
}
}
# the else
while(p!=NULL)
{
If ((p - & gt; Data) & gt; Mink& & p-> Data{
Q - & gt; Next=p - & gt; Next;
Free (p);
P=q - & gt; Next;
}
The else
{
Q=p;
P=p - & gt; Next;
//break;
}

}
# endif

return 1;
}

Int main ()
{
Int num [12]={0,2,3,6,13,21,33,37,45,66,99, 1};
int i;
Printf (" the original sequence: ");
for(i=0; i<11. I++)
Printf (" % d ", num [I]);
Int mink=0, maxk=0;
Printf (" \ n please enter remove elements lower mink: \ n ");
The scanf (" % d ", & amp; Mink);
Printf (" please enter remove upper bound element maxk: \ n ");
The scanf (" % d ", & amp; Maxk);
Linklist L;
CreatList (& amp; L, num);
ListDelete_L (L, mink, maxk);
Linklist p=L;
P=p - & gt; Next;
Printf (" now the sequence: ");
while(p!=NULL)
{
Printf (" % d ", p - & gt; The data);
P=p - & gt; Next;
}
}

For your reference ~

CodePudding user response:

The
reference 1/f, confident boy reply:
 # include & lt; stdio.h> 
#include

Typedef struct Lnode//define singly linked list storage structure
{
The int data;
Struct Lnode * next;
} Lnode * linklist;

Void CreatList (linklist * L, int num [])//to create a list
{
(* L)=(linklist) malloc (sizeof (Lnode));//set up leading the singly linked list of nodes
if(!
(* L).exit(1);
(* L) - & gt; Next=NULL;

int i=0;
Linklist p, q=* L;

While (num [I]!=1) terminated//data for 1
{
P=(Lnode *) malloc (sizeof (Lnode));
p-> data=https://bbs.csdn.net/topics/num [I];
Q - & gt; Next=p;
p-> Next=NULL;
Q=p;
i++;
}
}

Void chushu linklist (L)
{
Linklist r=L;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull