Queue implementation and array resizing using C++ The 2019 Stack Overflow Developer Survey Results Are InWhat are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhy can templates only be implemented in the header file?What is the effect of extern “C” in C++?What is the “-->” operator in C++?Easiest way to convert int to string in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?Why is it faster to process a sorted array than an unsorted array?

Is "plugging out" electronic devices an American expression?

Spanish for "widget"

What is the use of option -o in the useradd command?

Patience, young "Padovan"

Is this food a bread or a loaf?

How was Skylab's orbit inclination chosen?

Why is Grand Jury testimony secret?

How are circuits which use complex ICs normally simulated?

"What time...?" or "At what time...?" - what is more grammatically correct?

If the Wish spell is used to duplicate the effect of Simulacrum, are existing duplicates destroyed?

"Riffle" two strings

Can't find the latex code for the ⍎ (down tack jot) symbol

Should I write numbers in words or as numerals when there are multiple next to each other?

What tool would a Roman-age civilization have to grind silver and other metals into dust?

How can I create a character who can assume the widest possible range of creature sizes?

How to make payment on the internet without leaving a money trail?

Access elements in std::string where positon of string is greater than its size

Can distinct morphisms between curves induce the same morphism on singular cohomology?

Time travel alters history but people keep saying nothing's changed

How can I fix this gap between bookcases I made?

Where to refill my bottle in India?

On the insanity of kings as an argument against monarchy

Geography at the pixel level

Are USB sockets on wall outlets live all the time, even when the switch is off?



Queue implementation and array resizing using C++



The 2019 Stack Overflow Developer Survey Results Are InWhat are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhy can templates only be implemented in the header file?What is the effect of extern “C” in C++?What is the “-->” operator in C++?Easiest way to convert int to string in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?Why is it faster to process a sorted array than an unsorted array?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















The code is supposed to do queue functions which I got right.



The only problem I am having is: I am supposed to double the array size to twice its original size once the array gets completely filled.



I have coded for it but still getting garbage values when I try to put in more values than the original array size. So the problem seems to be in the inc() function below:



#ifndef Q_H_
#define Q_H_

#include <iostream>
using namespace std;



template <class elemType>
class arrayQueue

int size;
int *array;
int front;
int back;
int count;

public:
arrayQueue(elemType size)

this->size = size;
array = new int[size];
front = 0;
back = -1;
count=0;


bool isEmpty()

return (max()==0);


bool isFull()
return (max()==size);


void enqueue(elemType entry)

cout << "enqueue " << entry;

if(isEmpty())

front = back = 0;
array[back] = entry;
count++;

else

back = (back+1) % size;
array[back] = entry;
count++;

cout << endl;


int maxsize()

return count;


void dequeue()
cout << "dequeue : " << Front();
if(isEmpty())

cout << " error : empty";

else if(back == front)

back = front = -1;

else

front = (front+1) % size;
count--;

cout << endl;


void print()

if(isEmpty())

cout << "Queue is empty";

else

for(int i = front; i<count; i++)

cout << array[i] << " ";

cout << array[back];


//cout<<"count is:" <<count<<endl;
cout << endl;


int Front()


if(front == -1)

cout<<"Queue is emptyn";
return -1;

return array[front];



int Back()

if(back==-1)

cout<<"Queue is full";

return array[back];


int max()

return count;
cout <<"count: " <<count;



void inc()

int newsize = this->size*2;

elemType *temp = new elemType[newsize];



for (int i=0; i<this->count;i++)

temp[i]=this->array[(front+i) % size];


delete [] this->array;
this->array=temp;
this->count=newsize;

// front=array[front]; //0
//front = 0;
//back=count;





;



#endif /* Q_H_ */


I would really appreciate help with this.










share|improve this question



















  • 1





    In incyou don’t update this->size

    – Johnny Mopp
    Mar 22 at 2:21

















0















The code is supposed to do queue functions which I got right.



The only problem I am having is: I am supposed to double the array size to twice its original size once the array gets completely filled.



I have coded for it but still getting garbage values when I try to put in more values than the original array size. So the problem seems to be in the inc() function below:



#ifndef Q_H_
#define Q_H_

#include <iostream>
using namespace std;



template <class elemType>
class arrayQueue

int size;
int *array;
int front;
int back;
int count;

public:
arrayQueue(elemType size)

this->size = size;
array = new int[size];
front = 0;
back = -1;
count=0;


bool isEmpty()

return (max()==0);


bool isFull()
return (max()==size);


void enqueue(elemType entry)

cout << "enqueue " << entry;

if(isEmpty())

front = back = 0;
array[back] = entry;
count++;

else

back = (back+1) % size;
array[back] = entry;
count++;

cout << endl;


int maxsize()

return count;


void dequeue()
cout << "dequeue : " << Front();
if(isEmpty())

cout << " error : empty";

else if(back == front)

back = front = -1;

else

front = (front+1) % size;
count--;

cout << endl;


void print()

if(isEmpty())

cout << "Queue is empty";

else

for(int i = front; i<count; i++)

cout << array[i] << " ";

cout << array[back];


//cout<<"count is:" <<count<<endl;
cout << endl;


int Front()


if(front == -1)

cout<<"Queue is emptyn";
return -1;

return array[front];



int Back()

if(back==-1)

cout<<"Queue is full";

return array[back];


int max()

return count;
cout <<"count: " <<count;



void inc()

int newsize = this->size*2;

elemType *temp = new elemType[newsize];



for (int i=0; i<this->count;i++)

temp[i]=this->array[(front+i) % size];


delete [] this->array;
this->array=temp;
this->count=newsize;

// front=array[front]; //0
//front = 0;
//back=count;





;



#endif /* Q_H_ */


I would really appreciate help with this.










share|improve this question



















  • 1





    In incyou don’t update this->size

    – Johnny Mopp
    Mar 22 at 2:21













0












0








0








The code is supposed to do queue functions which I got right.



The only problem I am having is: I am supposed to double the array size to twice its original size once the array gets completely filled.



I have coded for it but still getting garbage values when I try to put in more values than the original array size. So the problem seems to be in the inc() function below:



#ifndef Q_H_
#define Q_H_

#include <iostream>
using namespace std;



template <class elemType>
class arrayQueue

int size;
int *array;
int front;
int back;
int count;

public:
arrayQueue(elemType size)

this->size = size;
array = new int[size];
front = 0;
back = -1;
count=0;


bool isEmpty()

return (max()==0);


bool isFull()
return (max()==size);


void enqueue(elemType entry)

cout << "enqueue " << entry;

if(isEmpty())

front = back = 0;
array[back] = entry;
count++;

else

back = (back+1) % size;
array[back] = entry;
count++;

cout << endl;


int maxsize()

return count;


void dequeue()
cout << "dequeue : " << Front();
if(isEmpty())

cout << " error : empty";

else if(back == front)

back = front = -1;

else

front = (front+1) % size;
count--;

cout << endl;


void print()

if(isEmpty())

cout << "Queue is empty";

else

for(int i = front; i<count; i++)

cout << array[i] << " ";

cout << array[back];


//cout<<"count is:" <<count<<endl;
cout << endl;


int Front()


if(front == -1)

cout<<"Queue is emptyn";
return -1;

return array[front];



int Back()

if(back==-1)

cout<<"Queue is full";

return array[back];


int max()

return count;
cout <<"count: " <<count;



void inc()

int newsize = this->size*2;

elemType *temp = new elemType[newsize];



for (int i=0; i<this->count;i++)

temp[i]=this->array[(front+i) % size];


delete [] this->array;
this->array=temp;
this->count=newsize;

// front=array[front]; //0
//front = 0;
//back=count;





;



#endif /* Q_H_ */


I would really appreciate help with this.










share|improve this question
















The code is supposed to do queue functions which I got right.



The only problem I am having is: I am supposed to double the array size to twice its original size once the array gets completely filled.



I have coded for it but still getting garbage values when I try to put in more values than the original array size. So the problem seems to be in the inc() function below:



#ifndef Q_H_
#define Q_H_

#include <iostream>
using namespace std;



template <class elemType>
class arrayQueue

int size;
int *array;
int front;
int back;
int count;

public:
arrayQueue(elemType size)

this->size = size;
array = new int[size];
front = 0;
back = -1;
count=0;


bool isEmpty()

return (max()==0);


bool isFull()
return (max()==size);


void enqueue(elemType entry)

cout << "enqueue " << entry;

if(isEmpty())

front = back = 0;
array[back] = entry;
count++;

else

back = (back+1) % size;
array[back] = entry;
count++;

cout << endl;


int maxsize()

return count;


void dequeue()
cout << "dequeue : " << Front();
if(isEmpty())

cout << " error : empty";

else if(back == front)

back = front = -1;

else

front = (front+1) % size;
count--;

cout << endl;


void print()

if(isEmpty())

cout << "Queue is empty";

else

for(int i = front; i<count; i++)

cout << array[i] << " ";

cout << array[back];


//cout<<"count is:" <<count<<endl;
cout << endl;


int Front()


if(front == -1)

cout<<"Queue is emptyn";
return -1;

return array[front];



int Back()

if(back==-1)

cout<<"Queue is full";

return array[back];


int max()

return count;
cout <<"count: " <<count;



void inc()

int newsize = this->size*2;

elemType *temp = new elemType[newsize];



for (int i=0; i<this->count;i++)

temp[i]=this->array[(front+i) % size];


delete [] this->array;
this->array=temp;
this->count=newsize;

// front=array[front]; //0
//front = 0;
//back=count;





;



#endif /* Q_H_ */


I would really appreciate help with this.







c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 2:26









Strom

2,498524




2,498524










asked Mar 22 at 2:16









AyushAyush

31




31







  • 1





    In incyou don’t update this->size

    – Johnny Mopp
    Mar 22 at 2:21












  • 1





    In incyou don’t update this->size

    – Johnny Mopp
    Mar 22 at 2:21







1




1





In incyou don’t update this->size

– Johnny Mopp
Mar 22 at 2:21





In incyou don’t update this->size

– Johnny Mopp
Mar 22 at 2:21












2 Answers
2






active

oldest

votes


















0














three small changes:




  1. enqueue method: inc when isFull



    if (isFull())

    inc();



  2. print method: print every element from front to back



  3. inc method: copy every element from front to back, and reset front and back index



    void inc()

    int newsize = this->size*2;

    elemType *temp = new elemType[newsize];

    // ******* IMPORTANT ******
    // copy count elements
    for (int i = 0; i < count; ++i)
    int index = (front + i) % size;
    temp[i] = array[index];

    front = 0;
    back = count - 1;
    delete []array;
    array=temp;
    count=newsize;




 template <class elemType>
class arrayQueue

int size;
int *array;
int front;
int back;
int count;
public:
arrayQueue(elemType size)

this->size = size;
array = new int[size];
front = 0;
back = -1;
count=0;


bool isEmpty()

return (max()==0);


bool isFull()
return (max()==size);


void enqueue(elemType entry)

cout << "enqueue " << entry;

if(isEmpty())

front = back = 0;
array[back] = entry;
count++;

else

if (isFull())
inc();

back = (back+1) % size;
array[back] = entry;
count++;

cout << endl;


int maxsize()

return count;


void dequeue()
cout << "dequeue : " << Front();
if(isEmpty())

cout << " error : empty";

else if(back == front)

back = front = -1;

else

front = (front+1) % size;
count--;

cout << endl;


void print()

if(isEmpty())

cout << "Queue is empty";

else

// ******* IMPORTANT ******
for (int i = 0; i < count; ++i)
int index = (front + i) % size;
cout << array[index] << " ";


//cout<<"count is:" <<count<<endl;
cout << endl;


int Front()


if(front == -1)

cout<<"Queue is emptyn";
return -1;

return array[front];



int Back()

if(back==-1)

cout<<"Queue is full";

return array[back];


int max()

return count;
cout <<"count: " <<count;



void inc()

int newsize = this->size*2;

elemType *temp = new elemType[newsize];

// ******* IMPORTANT ******
// copy count elements
for (int i = 0; i < count; ++i)
int index = (front + i) % size;
temp[i] = array[index];


front = 0;
back = count - 1;
delete []array;
array = temp;
count = newsize;

;





share|improve this answer






























    0














    Since you move elements to the beginning of the newly allocated array, inc needs to update front and back to refer to their respective new positions.



    Also, you're updating count to be the new size instead of size.






    share|improve this answer























    • Where should back refer to in this case?

      – Ayush
      Mar 22 at 3:00











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291935%2fqueue-implementation-and-array-resizing-using-c%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    three small changes:




    1. enqueue method: inc when isFull



      if (isFull())

      inc();



    2. print method: print every element from front to back



    3. inc method: copy every element from front to back, and reset front and back index



      void inc()

      int newsize = this->size*2;

      elemType *temp = new elemType[newsize];

      // ******* IMPORTANT ******
      // copy count elements
      for (int i = 0; i < count; ++i)
      int index = (front + i) % size;
      temp[i] = array[index];

      front = 0;
      back = count - 1;
      delete []array;
      array=temp;
      count=newsize;




     template <class elemType>
    class arrayQueue

    int size;
    int *array;
    int front;
    int back;
    int count;
    public:
    arrayQueue(elemType size)

    this->size = size;
    array = new int[size];
    front = 0;
    back = -1;
    count=0;


    bool isEmpty()

    return (max()==0);


    bool isFull()
    return (max()==size);


    void enqueue(elemType entry)

    cout << "enqueue " << entry;

    if(isEmpty())

    front = back = 0;
    array[back] = entry;
    count++;

    else

    if (isFull())
    inc();

    back = (back+1) % size;
    array[back] = entry;
    count++;

    cout << endl;


    int maxsize()

    return count;


    void dequeue()
    cout << "dequeue : " << Front();
    if(isEmpty())

    cout << " error : empty";

    else if(back == front)

    back = front = -1;

    else

    front = (front+1) % size;
    count--;

    cout << endl;


    void print()

    if(isEmpty())

    cout << "Queue is empty";

    else

    // ******* IMPORTANT ******
    for (int i = 0; i < count; ++i)
    int index = (front + i) % size;
    cout << array[index] << " ";


    //cout<<"count is:" <<count<<endl;
    cout << endl;


    int Front()


    if(front == -1)

    cout<<"Queue is emptyn";
    return -1;

    return array[front];



    int Back()

    if(back==-1)

    cout<<"Queue is full";

    return array[back];


    int max()

    return count;
    cout <<"count: " <<count;



    void inc()

    int newsize = this->size*2;

    elemType *temp = new elemType[newsize];

    // ******* IMPORTANT ******
    // copy count elements
    for (int i = 0; i < count; ++i)
    int index = (front + i) % size;
    temp[i] = array[index];


    front = 0;
    back = count - 1;
    delete []array;
    array = temp;
    count = newsize;

    ;





    share|improve this answer



























      0














      three small changes:




      1. enqueue method: inc when isFull



        if (isFull())

        inc();



      2. print method: print every element from front to back



      3. inc method: copy every element from front to back, and reset front and back index



        void inc()

        int newsize = this->size*2;

        elemType *temp = new elemType[newsize];

        // ******* IMPORTANT ******
        // copy count elements
        for (int i = 0; i < count; ++i)
        int index = (front + i) % size;
        temp[i] = array[index];

        front = 0;
        back = count - 1;
        delete []array;
        array=temp;
        count=newsize;




       template <class elemType>
      class arrayQueue

      int size;
      int *array;
      int front;
      int back;
      int count;
      public:
      arrayQueue(elemType size)

      this->size = size;
      array = new int[size];
      front = 0;
      back = -1;
      count=0;


      bool isEmpty()

      return (max()==0);


      bool isFull()
      return (max()==size);


      void enqueue(elemType entry)

      cout << "enqueue " << entry;

      if(isEmpty())

      front = back = 0;
      array[back] = entry;
      count++;

      else

      if (isFull())
      inc();

      back = (back+1) % size;
      array[back] = entry;
      count++;

      cout << endl;


      int maxsize()

      return count;


      void dequeue()
      cout << "dequeue : " << Front();
      if(isEmpty())

      cout << " error : empty";

      else if(back == front)

      back = front = -1;

      else

      front = (front+1) % size;
      count--;

      cout << endl;


      void print()

      if(isEmpty())

      cout << "Queue is empty";

      else

      // ******* IMPORTANT ******
      for (int i = 0; i < count; ++i)
      int index = (front + i) % size;
      cout << array[index] << " ";


      //cout<<"count is:" <<count<<endl;
      cout << endl;


      int Front()


      if(front == -1)

      cout<<"Queue is emptyn";
      return -1;

      return array[front];



      int Back()

      if(back==-1)

      cout<<"Queue is full";

      return array[back];


      int max()

      return count;
      cout <<"count: " <<count;



      void inc()

      int newsize = this->size*2;

      elemType *temp = new elemType[newsize];

      // ******* IMPORTANT ******
      // copy count elements
      for (int i = 0; i < count; ++i)
      int index = (front + i) % size;
      temp[i] = array[index];


      front = 0;
      back = count - 1;
      delete []array;
      array = temp;
      count = newsize;

      ;





      share|improve this answer

























        0












        0








        0







        three small changes:




        1. enqueue method: inc when isFull



          if (isFull())

          inc();



        2. print method: print every element from front to back



        3. inc method: copy every element from front to back, and reset front and back index



          void inc()

          int newsize = this->size*2;

          elemType *temp = new elemType[newsize];

          // ******* IMPORTANT ******
          // copy count elements
          for (int i = 0; i < count; ++i)
          int index = (front + i) % size;
          temp[i] = array[index];

          front = 0;
          back = count - 1;
          delete []array;
          array=temp;
          count=newsize;




         template <class elemType>
        class arrayQueue

        int size;
        int *array;
        int front;
        int back;
        int count;
        public:
        arrayQueue(elemType size)

        this->size = size;
        array = new int[size];
        front = 0;
        back = -1;
        count=0;


        bool isEmpty()

        return (max()==0);


        bool isFull()
        return (max()==size);


        void enqueue(elemType entry)

        cout << "enqueue " << entry;

        if(isEmpty())

        front = back = 0;
        array[back] = entry;
        count++;

        else

        if (isFull())
        inc();

        back = (back+1) % size;
        array[back] = entry;
        count++;

        cout << endl;


        int maxsize()

        return count;


        void dequeue()
        cout << "dequeue : " << Front();
        if(isEmpty())

        cout << " error : empty";

        else if(back == front)

        back = front = -1;

        else

        front = (front+1) % size;
        count--;

        cout << endl;


        void print()

        if(isEmpty())

        cout << "Queue is empty";

        else

        // ******* IMPORTANT ******
        for (int i = 0; i < count; ++i)
        int index = (front + i) % size;
        cout << array[index] << " ";


        //cout<<"count is:" <<count<<endl;
        cout << endl;


        int Front()


        if(front == -1)

        cout<<"Queue is emptyn";
        return -1;

        return array[front];



        int Back()

        if(back==-1)

        cout<<"Queue is full";

        return array[back];


        int max()

        return count;
        cout <<"count: " <<count;



        void inc()

        int newsize = this->size*2;

        elemType *temp = new elemType[newsize];

        // ******* IMPORTANT ******
        // copy count elements
        for (int i = 0; i < count; ++i)
        int index = (front + i) % size;
        temp[i] = array[index];


        front = 0;
        back = count - 1;
        delete []array;
        array = temp;
        count = newsize;

        ;





        share|improve this answer













        three small changes:




        1. enqueue method: inc when isFull



          if (isFull())

          inc();



        2. print method: print every element from front to back



        3. inc method: copy every element from front to back, and reset front and back index



          void inc()

          int newsize = this->size*2;

          elemType *temp = new elemType[newsize];

          // ******* IMPORTANT ******
          // copy count elements
          for (int i = 0; i < count; ++i)
          int index = (front + i) % size;
          temp[i] = array[index];

          front = 0;
          back = count - 1;
          delete []array;
          array=temp;
          count=newsize;




         template <class elemType>
        class arrayQueue

        int size;
        int *array;
        int front;
        int back;
        int count;
        public:
        arrayQueue(elemType size)

        this->size = size;
        array = new int[size];
        front = 0;
        back = -1;
        count=0;


        bool isEmpty()

        return (max()==0);


        bool isFull()
        return (max()==size);


        void enqueue(elemType entry)

        cout << "enqueue " << entry;

        if(isEmpty())

        front = back = 0;
        array[back] = entry;
        count++;

        else

        if (isFull())
        inc();

        back = (back+1) % size;
        array[back] = entry;
        count++;

        cout << endl;


        int maxsize()

        return count;


        void dequeue()
        cout << "dequeue : " << Front();
        if(isEmpty())

        cout << " error : empty";

        else if(back == front)

        back = front = -1;

        else

        front = (front+1) % size;
        count--;

        cout << endl;


        void print()

        if(isEmpty())

        cout << "Queue is empty";

        else

        // ******* IMPORTANT ******
        for (int i = 0; i < count; ++i)
        int index = (front + i) % size;
        cout << array[index] << " ";


        //cout<<"count is:" <<count<<endl;
        cout << endl;


        int Front()


        if(front == -1)

        cout<<"Queue is emptyn";
        return -1;

        return array[front];



        int Back()

        if(back==-1)

        cout<<"Queue is full";

        return array[back];


        int max()

        return count;
        cout <<"count: " <<count;



        void inc()

        int newsize = this->size*2;

        elemType *temp = new elemType[newsize];

        // ******* IMPORTANT ******
        // copy count elements
        for (int i = 0; i < count; ++i)
        int index = (front + i) % size;
        temp[i] = array[index];


        front = 0;
        back = count - 1;
        delete []array;
        array = temp;
        count = newsize;

        ;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 2:51









        pexeerpexeer

        40028




        40028























            0














            Since you move elements to the beginning of the newly allocated array, inc needs to update front and back to refer to their respective new positions.



            Also, you're updating count to be the new size instead of size.






            share|improve this answer























            • Where should back refer to in this case?

              – Ayush
              Mar 22 at 3:00















            0














            Since you move elements to the beginning of the newly allocated array, inc needs to update front and back to refer to their respective new positions.



            Also, you're updating count to be the new size instead of size.






            share|improve this answer























            • Where should back refer to in this case?

              – Ayush
              Mar 22 at 3:00













            0












            0








            0







            Since you move elements to the beginning of the newly allocated array, inc needs to update front and back to refer to their respective new positions.



            Also, you're updating count to be the new size instead of size.






            share|improve this answer













            Since you move elements to the beginning of the newly allocated array, inc needs to update front and back to refer to their respective new positions.



            Also, you're updating count to be the new size instead of size.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 22 at 2:20









            1201ProgramAlarm1201ProgramAlarm

            17.9k52740




            17.9k52740












            • Where should back refer to in this case?

              – Ayush
              Mar 22 at 3:00

















            • Where should back refer to in this case?

              – Ayush
              Mar 22 at 3:00
















            Where should back refer to in this case?

            – Ayush
            Mar 22 at 3:00





            Where should back refer to in this case?

            – Ayush
            Mar 22 at 3:00

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291935%2fqueue-implementation-and-array-resizing-using-c%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript