MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

CPP/questions/InsertionSort.cpp:10–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8// it is slow sorting algorithm
9using namespace std;
10int main()
11{
12 vector<int>v;
13 int n;
14 cout<<"Enter size of array/vector\n";
15 cin>>n;
16 for(int i=0;i<n;i++)
17 {
18 int temp;
19 cin>>temp;
20 v.push_back(temp);
21 }
22 for(int i=1;i<n;i++)
23 {
24 int val=v[i];
25 int j=i;
26 while(j>0&&v[j-1]>val)
27 {
28 v[j]=v[j-1];
29 j--;
30 }
31 v[j]=val;
32 }
33 for(int i=0;i<n;i++)
34 cout<<v[i]<<" ";
35}

Callers

nothing calls this directly

Calls 1

push_backMethod · 0.80

Tested by

no test coverage detected