Home > Back-end >  Help remove a great god list are deleted
Help remove a great god list are deleted

Time:10-17

//page table entries structure
Typedef struct _pagetableitem
{
Unsigned pagenum;//page number
Unsigned blocknum; No.//block
} pgtabitem;//page table
Typedef pgtabitem * pagetable;
//request table structure
Typedef struct _reqtable
{
Unsigned pid; No.//process
Unsigned reqpagenum;//request page number
Pagetable pgtabadr;//page table starting address
Bool state;//state
} reqtabitem;


List Reqtable;

I want to delete a specified in the list the object of the process, how to delete?

Reqtabitem temp.

List : : iterator pos=reqtable. The begin ();

For (pos=reqtable. The begin (); Pos!=reqtable. End (); Pos++)
{
If (pos (*). Pid==pid)
{
flag=true;
Temp=* pos.
Pos (*). The state=false;
break;
}

}

Reqtabitem. Remove (temp)

What is wrong, error

CodePudding user response:

Reqtabitem temp.
Reqtabitem. Remove (temp)//here is can't use,

Reqtable should be STD: : list , call a list of the remove method can delete the elements in the list
If you want to delete a list and all elements of temp is equal, so should use the STD: : remove_if method,

I want to delete a specified in the list the object of the process, how to delete?
A: with STD: : find find this element, then use the list of the remove method delete it

CodePudding user response:

Finally I use reqtable. Erase (pos); The deleted

CodePudding user response:

Using reqtable. Erase (pos); Ok, always delete List elements will be done,

CodePudding user response:

 remove is direct delete value 

We use iterative access erase, and must be i++, skip the next, or complains

Cry to for a long time didn't understand

For (list : : iterator I=list_i. The begin (); The I!=list_i. End (); + + I)
{
Cout & lt; <"I=" & lt; <* I & lt; List_i. Erase (i++);
}
  • Related