Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C
Expertise: Advanced
Dec 11, 2003



Application Security Testing: An Integral Part of DevOps

Remove an Element in a Sorted Array

To remove an element at a given position in a sorted array, shift all the elements above it down one position.

void erase(int a[], int& n, int index) {
   // function:
   //    Removes key at a[index], shifting other values down as necessary.
   //    Updates number of elements in a.
   // parameters:
   //    a       inout  array of values.
   //    n       inout  number of values in a, a[0]..a[n-1]
   //    index   in     position to delete.
   // returns: nothing

   // Move all elements up down position.  i is destination.
   for (int i=index; i<n; i++) {
       a[i] = a[i+1];
   n--;             // update count of items in a
DevX Staff
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date