Skip to content
Snippets Groups Projects
Commit c84b73c3 authored by abivarma.kandiah's avatar abivarma.kandiah
Browse files

Add vector insert

parent 9d853de0
No related branches found
No related tags found
No related merge requests found
......@@ -26,5 +26,6 @@ type vector_pop(vector vec);
void vector_set(vector vec, int index, type element);
type vector_get(vector vec, int index);
type vector_remove(vector vec, int index);
void vector_insert(vector vec, type element, int index);
#endif
\ No newline at end of file
......@@ -41,7 +41,12 @@ int main()
vector_remove(test, 3);
printf("New Value at index 3 : %d \n", vector_get(test, 3));
//Test Vector Insert
vector_insert(test, 3, 3);
printf("New Value at index 3 and 4: %d, %d \n", vector_get(test, 3), vector_get(test, 4));
//Test Vector Empty
return 0;
}
\ No newline at end of file
......@@ -93,4 +93,19 @@ type vector_remove(vector vec, int index)
}
return tmp;
}
void vector_insert(vector vec, type element, int index)
{
assert(index < vec->length);
vec->length++;
for (int i = vec->length; i > index; i--) // Ex : 0 1 2 {3} 4 5 // Index 3 , lenght 6
{
vec->content[i] = vec->content[i-1];
}
vec->content[index] = element;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment