### N idea

Pages: 123
That's too hard to understand.
Sorry, algorithm, not @OP code.

I compiled & tested the debug version. Both two solution work correctly. :)

But the difference between mine and others :
My solution (from the algorithm) hmm... :

`| 0 | 1 | 2 | 3 | 4 | 5 |`

and we want to remove the 2, we swap it with the last element:
`| 0 | 1 | 5 | 4 | 3 | 2 |`

And the easy one :

`| 0 | 1 | 2 | 3 | 4 | 5 |`

and we want to remove the 2, we swap it with the last element:
`| 0 | 1 | 3 | 4 | 5 | 5 |`

Which is better? Here, debug program :
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152`` ``````#include #include #include #include using namespace std; const int SIZE = 10; //structure struct infoType { string fname; string lname; string streetAdd; string cityStateZ; string phone; int num; // Additional variable (Debug) }; //Other solution int remove( infoType tele[], int& size, int position_of_item_to_remove ) { for( int i = position_of_item_to_remove + 1 ; i < size ; ++i ) tele[i-1] = tele[i] ; return --size; } int main() { int choice; infoType tele[SIZE]; for(int i =0;i < SIZE;i++){tele[i].num = i+1; cout << i << " ";} cout << "\nPlease enter the number you want to delete : "; cin >> choice;choice-=1; //Because 1 2 3 not 0 1 2 //The first solution int size = SIZE; int nCount = 0; infoType temp[SIZE]; for( i = choice; i < size;i++){temp[nCount] = tele[i];nCount++;} for( i = choice; i < size;i++){nCount--;tele[i] = temp[nCount];} size--; //remove(tele,size,choice); for(int j =0;j < size;j++){cout << tele[j].num << " ";}cout << "\n";}``````
Last edited on
 //Jackson Marie's solution

You would be well advised to ignore this troll's posts.
 You would be well advised to ignore this troll's posts.

....................

I stand corrected. You said (I'm a troll?) I'm not a troll.
Any my mistake please correct.... :)
Topic archived. No new replies allowed.
Pages: 123