কম্পিউটার

STL এ সারি বাস্তবায়নের জন্য C++ প্রোগ্রাম


একটি সারি হল একটি রৈখিক কাঠামো যা ফার্স্ট ইন ফার্স্ট আউট (FIFO) ক্রম অনুসরণ করে যেখানে সারির উপাদানগুলিতে অপারেশনগুলি সঞ্চালিত হয়৷

অ্যালগরিদম

Functions used here:
   q.size() = Returns the size of queue.
   q.push() = It is used to insert elements to the queue.
   q.pop() = To pop out the value from the queue.
   q.front() = Returns the front element of the array.
   q.back() = Returns the back element of the array.

উদাহরণ কোড

#include<iostream>
#include <queue>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
   queue<int> q;
   int c, i;
   while (1) {
      cout<<"1.Size of the Queue"<<endl;
      cout<<"2.Insert Element into the Queue"<<endl;
      cout<<"3.Delete Element from the Queue"<<endl;
      cout<<"4.Front Element of the Queue"<<endl;
      cout<<"5.Last Element of the Queue"<<endl;
      cout<<"6.Exit"<<endl;
      cout<<"Enter your Choice: ";
      cin>>c;
      switch(c) {
         case 1:
            cout<<"Size of the Queue: ";
            cout<<q.size()<<endl;
         break;
         case 2:
            cout<<"Enter value to be inserted: ";
            cin>>i;
            q.push(i);
         break;
         case 3:
            i = q.front();
            q.pop();
            cout<<"Element "<<i<<" Deleted"<<endl;
         break;
         case 4:
            cout<<"Front Element of the Queue: ";
            cout<<q.front()<<endl;
         break;
         case 5:
            cout<<"Back Element of the Queue: ";
            cout<<q.back()<<endl;
         break;
         case 6:
            exit(1);
         break;
         default:
            cout<<"Wrong Choice"<<endl;
      }
   }
   return 0;
}

আউটপুট

1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 1
Size of the Queue: 0
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 2
Enter value to be inserted: 1
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 2
Enter value to be inserted: 2
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 3
Element 1 Deleted
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 2
Enter value to be inserted: 4
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 2
Enter value to be inserted: 7
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 2
Enter value to be inserted: 6
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 4
Front Element of the Queue: 2
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit

Enter your Choice: 5
Back Element of the Queue: 6
1.Size of the Queue
2.Insert Element into the Queue
3.Delete Element from the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 6
Exit code: 1

  1. STL-এ সেট_ইউনিয়ন বাস্তবায়নের জন্য C++ প্রোগ্রাম

  2. STL-এ সেট_সিমেট্রিক_ডিফারেন্স বাস্তবায়নের জন্য C++ প্রোগ্রাম

  3. STL-এ Set_Intersection বাস্তবায়নের জন্য C++ প্রোগ্রাম

  4. STL-এ সেট_ডিফারেন্স বাস্তবায়নের জন্য C++ প্রোগ্রাম