popBack and popFront

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pleatofthepants

    popBack and popFront

    I could use some help. I am writting two functions, one is popBack and
    one is popFront.

    popFront needs to remove a data element from the front of my data
    structure.
    popFront (T& n)
    {

    }
    popBack needs to remove a data element from the rear of my data
    structure
    popBack (T& n)
    {

    }

    I have two functions shiftRight and shiftLeft that will move the
    elements in the array right or left.

    void shiftRight()
    {
    //decrement this iteration
    for (int i = size; i >= 0; i--)
    {
    data[i] = data[i - 1];
    }
    size++;
    }
    void shiftLeft ()
    {
    for (int i = 0; i < size; i++)
    {
    data[i] = data[i + 1];
    }
    size--;
    }
  • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

    #2
    Re: popBack and popFront

    On 2008-03-26 21:35, pleatofthepants wrote:
    I could use some help. I am writting two functions, one is popBack and
    one is popFront.
    >
    popFront needs to remove a data element from the front of my data
    structure.
    popFront (T& n)
    {
    >
    }
    popBack needs to remove a data element from the rear of my data
    structure
    popBack (T& n)
    {
    >
    }
    >
    I have two functions shiftRight and shiftLeft that will move the
    elements in the array right or left.
    >
    void shiftRight()
    {
    //decrement this iteration
    for (int i = size; i >= 0; i--)
    {
    data[i] = data[i - 1];
    }
    size++;
    }
    void shiftLeft ()
    {
    for (int i = 0; i < size; i++)
    {
    data[i] = data[i + 1];
    }
    size--;
    }
    OK, and?

    Take a look in the FAQ, http://www.parashift.com/c++-faq-lite/,
    especially sections 5.2 and 5.8.

    --
    Erik Wikström

    Comment

    Working...