Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
1
170050020-170050046-170050058-git
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
KIRAN CHANDRAKANT DAPKAR
170050020-170050046-170050058-git
Commits
c547aff3
Commit
c547aff3
authored
Aug 26, 2018
by
NIRMAL RAJPUT
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update merge-sort to reflect API update
parent
a3dd9cd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
47 deletions
+33
-47
sorting.cpp
sorting.cpp
+33
-47
No files found.
sorting.cpp
View file @
c547aff3
#include<iostream>
#include<vector>
#include "sorting.h"
#include<iostream>
using
namespace
std
;
vector
<
int
>
merge_fun
(
vector
<
int
>
array1
,
vector
<
int
>
array2
){
int
n1
=
array1
.
size
(),
n2
=
array2
.
size
(),
count1
=
0
,
count2
=
0
;
vector
<
int
>
merged
(
n1
+
n2
);
for
(
int
i
=
0
;
i
<
n1
+
n2
;
i
++
){
if
(
count1
>=
n1
){
merged
[
i
]
=
array2
[
count2
];
count2
++
;
}
else
if
(
count2
>=
n2
){
merged
[
i
]
=
array1
[
count1
];
count1
++
;
}
else
{
if
(
array1
[
count1
]
<=
array2
[
count2
]){
merged
[
i
]
=
array1
[
count1
];
count1
++
;
}
else
{
merged
[
i
]
=
array2
[
count2
];
count2
++
;
}
}
}
return
merged
;
void
merge
(
vector
<
int
>&
inp
,
int
start
,
int
middle
,
int
end
)
{
int
p
=
start
,
q
=
middle
+
1
;
int
array
[
end
-
start
+
1
]
;
int
k
=
0
;
for
(
int
i
=
start
;
i
<=
end
;
i
++
)
{
if
(
p
>
middle
)
array
[
k
++
]
=
inp
[
q
++
]
;
else
if
(
q
>
end
)
array
[
k
++
]
=
inp
[
p
++
];
else
if
(
inp
[
p
]
<
inp
[
q
])
array
[
k
++
]
=
inp
[
p
++
];
else
array
[
k
++
]
=
inp
[
q
++
];
}
for
(
int
i
=
start
;
i
<=
end
;
i
++
){
inp
[
i
]
=
array
[
i
-
start
]
;
}
}
vector
<
int
>
sort_custom
(
vector
<
int
>
inp
){
int
n
=
inp
.
size
();
if
(
n
==
1
){
return
inp
;
}
else
{
int
n1
=
n
/
2
;
int
n2
=
n
-
n1
;
vector
<
int
>
array1
(
n1
),
array2
(
n2
);
for
(
int
i
=
0
;
i
<
n
;
i
++
){
if
(
i
<
n1
)
array1
[
i
]
=
inp
[
i
];
else
if
(
i
<
n1
+
n2
)
array2
[
i
-
n1
]
=
inp
[
i
];
}
vector
<
int
>
out1
=
sort_custom
(
array1
);
vector
<
int
>
out2
=
sort_custom
(
array2
);
vector
<
int
>
ans
=
merge_fun
(
out1
,
out2
);
return
ans
;
void
merge_sort
(
vector
<
int
>&
inp
,
int
start
,
int
end
)
{
if
(
start
<
end
){
int
middle
=
(
start
+
end
)
/
2
;
merge_sort
(
inp
,
start
,
middle
)
;
merge_sort
(
inp
,
middle
+
1
,
end
)
;
merge
(
inp
,
start
,
middle
,
end
);
}
}
vector
<
int
>
sort_custom
(
vector
<
int
>
inp
,
int
startidx
,
int
endidx
){
merge_sort
(
inp
,
startidx
,
endidx
)
;
return
inp
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment