[Algorithm] Design a link list with method: add, search and remove

struct Node{
	valatile int val;
	struct Node* valatile next;
	struct mutex lock;
}

bool remove(struct Node*head, int val)
{
	if (head==NULL)
		return false
	pre=head;
	cur=head.next;
	mutex_lock(pre.lock)
	mutex_lock(cur.lock)
	while (cur && cur.val!=val)
	{
		mutex_unlock(pre.lock)
		pre=cur
		cur=cur.next
		if (cur!=NULL)
			mutex_lock(cur.lock)
	}
	if (cur==NULL)
		mutex_unlock(pre)
	else
	{	
		pre.next=cur.next
		mutex_unlock(pre)
		mutex_unlock(cur)
	}
}
bool add(struct Node* head, val)
{
...
}
bool contain(struct Node*head, val)
{
...
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章