File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed 
CPP/Data Structures/queue Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ class Queue {
1414    Queue (int  capacity = 10 ) {
1515        this ->capacity  = capacity;
1616        sz = 0 ;
17-         head = - 1 ;
18-         tail = - 1 ;
17+         head = 0 ;
18+         tail = 0 ;
1919        arr = new  T[capacity];
2020    }
2121
@@ -28,14 +28,14 @@ class Queue {
2828    }
2929
3030    bool  full () {
31-         return  tail  == capacity;
31+         return  sz  == capacity;
3232    }
3333
3434    void  resize (int  cap) {
3535        if (cap < 1 ) cap = 1 ;
3636        T* narr = new  T[cap];
3737
38-         for (int  i=head ; i<tail ; i++) 
38+         for (int  i=0 ; i<sz ; i++) 
3939            narr[i] = arr[(head + i) % capacity];
4040        delete [] arr;
4141        arr = narr;
@@ -69,8 +69,8 @@ class Queue {
6969    }
7070
7171    void  display () {
72-         for (int  i=head ; i<=tail ; i++) {
73-             cout << arr[i ] << "  " 
72+         for (int  i=0 ; i<sz ; i++) {
73+             cout << arr[(head + i) % capacity ] << "  " 
7474        }
7575        cout << endl;
7676    }
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments