Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
O(1) 時間の複雑さで次の操作をサポートするスタックを実装する方法は?
先頭、末尾、および中間の要素へのポインタを含む LinkedList データ構造を使用します。
これにより、中間要素のプッシュ、ポップ、削除、および検索に O(1) 時間の複雑さが生じます。
唯一のトリックは、このデータ構造から要素を追加または削除するときに、「中間」要素ポインターを正しく移動することです。