MCPcopy Create free account
hub / github.com/devparthgarg/Data-Structures-and-Algorithms / insert

Function insert

05. Arrays/02 Insert/02 Insert.cpp:6–16  ·  view source on GitHub ↗

Time: O(n) insert at begin Time: O(1) insert at end

Source from the content-addressed store, hash-verified

4//Time: O(n) insert at begin
5//Time: O(1) insert at end
6int insert(int arr[], int n, int key, int pos)
7{
8 for (int i = n - 1; i >= pos - 1; i--)
9 {
10 arr[i + 1] = arr[i];
11 }
12 arr[pos - 1] = key;
13 n++;
14
15 return n;
16}
17
18void display(int arr[], int n)
19{

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected