On the realization of an algorithm for the Postgraduate entrance examination

topic description

there are n elements in an integer queue. Is there an n-independent method to delete a specific
element in this queue? If possible, please give your data structure and deletion algorithm, the algorithm is expressed by a function, the definition of the function is as follows; if
is not possible, please state your reason.
function definition:

void DeleteNode(ListNode *pListHead, ListNode *pToBeDeleted)
{
    // 
}

sources of topics and their own ideas

for the postgraduate entrance examination questions of Zhejiang University of Technology, I feel that it is impossible to have such an algorithm at all. But isn"t there no need to do that big problem at all?

Dec.20,2021

Have you given the definition of

ListNode, and how to write it if you don't know how to write it.

< hr >

this question is not for you to define the structure of ListNode, then the decisive two-way linked list can perfectly achieve the complexity of O (1). If you only use an one-way linked list, the complexity is O (n), because you have to traverse to find the previous node where the node was deleted.


as long as the pointers of the front and back nodes are recorded on the deleted node (this is your data structure), the time complexity has nothing to do with n.


I think it has nothing to do with n is nonsense. What he means is that
gives you a starting point and a node to delete the node from the linked list.

only need a loop. When current.next = = * target , point current.next to target.next .
if it's a two-way linked list, you can skip the starting point.


Bidirectional linked list for more information

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7b7c5d-29c9d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7b7c5d-29c9d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?