filhotecmail

MetodoAddC

Mar 3rd, 2021
681
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;  
  3.  
  4. class Queue {
  5.  //atributo
  6.  int size;  
  7.  int* queue;  
  8.  
  9.  //construtor
  10.  public:
  11.  Queue() {
  12.   size = 0;
  13.   queue = new int[100];
  14.  }
  15.  //metodos
  16.  void remove() {  
  17.   if (size == 0) {  
  18.    cout << "Queue is empty"<<endl;  
  19.    return;  
  20.   }  
  21.   else {  
  22.    for (int i = 0; i < size - 1; i++) {  
  23.     queue[i] = queue[i + 1];  
  24.    }  
  25.    size--;  
  26.   }  
  27.  }  
  28.  void print() {  
  29.   if (size == 0) {  
  30.    cout << "Queue is empty"<<endl;  
  31.    return;  
  32.   }  
  33.   for (int i = 0; i < size - 1; i++) {  
  34.    cout<<queue[i]<<" <- ";
  35.   }  
  36.   cout <<endl;
  37.  }
  38.  
  39.  public:
  40.   void add()
  41.   {  
  42.     item = 0;
  43.     for (int x = 0; x < size - 1 ; x++) {  
  44.     queue[x] = queue[x - 1];
  45.      
  46.    }  
  47.    size++;
  48.   }
  49. };  
  50.  
  51. int main() {  
  52.  Queue q;  
  53.  q.add(42); q.add(2); q.add(8); q.add(1);  
  54.  q.print();
  55.  q.remove();  
  56.  q.add(128);  
  57.  q.print();  
  58.  q.remove();  
  59.  q.remove();  
  60.  q.print();  
  61.  
  62.  return 0;  
  63. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×