কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে Queue-এ Clear অপারেশন


Queue: Clear Operation (সব এলিমেন্ট মুছে ফেলা)

Clear অপারেশন কিউর সব এলিমেন্ট একসাথে মুছে ফেলে এবং কিউকে খালি অবস্থায় ফেরত আনে।

Clear মেথড ইমপ্লিমেন্টেশন

class Queue {
  constructor(maxSize = 10) {
    this.maxSize = maxSize;
    this.container = [];
  }

  // ... enqueue, dequeue, peek, isEmpty, isFull, display ...

  // Clear Operation
  clear() {
    this.container = []; // নতুন খালি অ্যারে অ্যাসাইন
  }
}

টেস্টিং উদাহরণ

const q = new Queue(5);

q.enqueue(10);
q.enqueue(20);
q.enqueue(30);

console.log("Before clear:");
q.display(); // [ 10, 20, 30 ]

q.clear();

console.log("After clear:");
q.display(); // []

console.log("Is Empty:", q.isEmpty()); // true
console.log("Size:", q.size());        // 0

আউটপুট

Before clear:
[ 10, 20, 30 ]
After clear:
[ ]
Is Empty: true
Size: 0

Clear Implementation Options

// ১. নতুন অ্যারে অ্যাসাইন (Recommended)
clear() {
  this.container = [];
}

// ২. Length = 0 (Same reference, faster)
clear() {
  this.container.length = 0;
}

// ৩. Splice
clear() {
  this.container.splice(0, this.container.length);
}

সব পদ্ধতির ফলাফল একই। this.container = [] সবচেয়ে ক্লিয়ার এবং সাধারণ।

  1. জাভাস্ক্রিপ্টে কিউ (Queue) থেকে ডিকিউ (Dequeue) অপারেশন

  2. জাভাস্ক্রিপ্টে কিউ (Queue-এ) এলিমেন্ট যোগ করা (Enqueue)

  3. জাভাস্ক্রিপ্টে কিউ (Queue) বাস্তবায়ন

  4. Windows 10-এ আটকে যাওয়া প্রিন্ট কিউ ফোর্সফুলি ক্লিয়ার করুন