まず、アルゴリズムの疑似コードを記述し、実際に関数を実装します。これは独立してテストできます。あなたのリストとノードを仮定
for each node in list1
{
if (list2 contains node)
{
remove node from list1
}
}
のようなものに定義されています:
一般的な擬似コードは次のようなものになるだろう
:
だから、
struct Node
{
struct Node *next;
struct Node *prev;
int number;
}
struct List
{
struct Node *head;
}
// these should be instantiated somewhere
struct List* list1;
struct List* list2;
を、関数のスケルトンは次のようなものになるだろう
struct Node* node = list1->head;
while (node != null)
{
// prepare the next node early
struct Node* next = node->next;
// check if list2 contains a matching node
if (match(list2, node->number))
{
// remove the node properly,
// updating whatever you need to update
remove(list1, node);
}
// if it's circular, check if this
// is the last node
if (next == list1->head)
break;
node = next;
}
これで、2つの機能、すなわち
// returns true if any node in list contains the specified number
bool match(struct List* list, int number);
// removes the node from the list
void remove(struct List* list, struct Node* node);
あなたが何を求めているのかはっきりしません。何か試しましたか? –
私は頭を持つ2つの円形の二重リンクリストを持っています。 L1:40 100 90 20 10 32 66 L2:60 10 46 30 80 90 第2リストにある値を最初のリストから削除したいとします。最初のリストは次のようになります。 L1:40 100 20 32 66 この除外を行うために、リストの操作方法を知りたいと思います。私は擬似コードの概念を望んでいました。私はCでコードする必要がありますが、私はアルゴリズムを理解していません。私は以前のやり方を理解する必要があります。 –
「手」とは何ですか?あなたは "頭"を意味しましたか? – Groo