CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 21

Threaded View

  1. #12
    Join Date
    May 2009
    Posts
    2,413

    Re: Compacting an array in C++

    Quote Originally Posted by wael.salman View Post
    what do you mean by:

    First you write code that just iterates through the whole array and copies each array number to itself using the two indexes.????
    Like this,

    Code:
    int w=0; // write index
    int r=0; // read index
    while (r < array_size) {
       array[w++] = array[r]; // copy number, increment write index by 1
       r++; // increment read index by 1
    }
    The array and array_size are defined elsewhere.

    The above just copies the array on itself. You modify it so the r index is incremented in each iteration to skip a whole sequence of equal numbers. The w index is incremented as before. The effect is that only one number of any equal number sequence is copied.
    Last edited by nuzzle; October 23rd, 2009 at 07:23 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured