Skip to content

Instantly share code, notes, and snippets.

@nahiyan
Created November 21, 2016 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahiyan/1cae871bbe07e0c53a1c0fd3065dc1bf to your computer and use it in GitHub Desktop.
Save nahiyan/1cae871bbe07e0c53a1c0fd3065dc1bf to your computer and use it in GitHub Desktop.
#include <stdio.h>
// 1 2 3 4 5
// 1 3 4 5 -1
void deleteItem (int list[], int z, int index) {
int i = index;
while (i < z) {
if ((i + 1) < z) // if there's an item on the left
list[i] = list[i + 1];
else
list[i] = -1;
i++;
}
}
int main () {
int list[] = {1, 2, 3, 4, 5}, i;
deleteItem(list, 5, 1);
for (i = 0; i < 5; i++) {
printf("%d\n", list[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment