Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
1
170050033-170050062-170050101-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
0
Merge Requests
0
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
LAKSHYA KUMAR
170050033-170050062-170050101-git
Commits
acb1a831
Commit
acb1a831
authored
Aug 26, 2018
by
AMISH JAIN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change implementation to merge-sort
parent
b440396f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
19 deletions
+48
-19
sorting.cpp
sorting.cpp
+48
-19
No files found.
sorting.cpp
View file @
acb1a831
#include <iostream>
#include "sorting.h"
using
namespace
std
;
vector
<
int
>
sort_custom
(
vector
<
int
>
v
)
vector
<
int
>
merge
(
vector
<
int
>
left
,
vector
<
int
>
right
)
{
for
(
int
i
=
0
;
i
<
v
.
size
();
i
++
)
{
int
count
=
0
;
for
(
int
j
=
0
;
j
<
v
.
size
()
-
1
;
j
++
)
{
if
(
v
[
j
]
>
v
[
j
+
1
])
{
count
++
;
int
temp
=
v
[
j
];
v
[
j
]
=
v
[
j
+
1
];
v
[
j
+
1
]
=
temp
;
vector
<
int
>
result
;
while
((
int
)
left
.
size
()
>
0
||
(
int
)
right
.
size
()
>
0
)
{
if
((
int
)
left
.
size
()
>
0
&&
(
int
)
right
.
size
()
>
0
)
{
if
((
int
)
left
.
front
()
<=
(
int
)
right
.
front
())
{
result
.
push_back
((
int
)
left
.
front
());
left
.
erase
(
left
.
begin
());
}
else
{
result
.
push_back
((
int
)
right
.
front
());
right
.
erase
(
right
.
begin
());
}
if
(
count
==
0
)
{
return
v
;
}
else
if
((
int
)
left
.
size
()
>
0
)
{
for
(
int
i
=
0
;
i
<
(
int
)
left
.
size
();
i
++
)
result
.
push_back
(
left
[
i
]);
break
;
}
else
if
((
int
)
right
.
size
()
>
0
)
{
for
(
int
i
=
0
;
i
<
(
int
)
right
.
size
();
i
++
)
result
.
push_back
(
right
[
i
]);
break
;
}
}
return
v
;
return
result
;
}
vector
<
int
>
sort_custom
(
vector
<
int
>
m
)
{
if
(
m
.
size
()
<=
1
)
return
m
;
vector
<
int
>
left
,
right
,
result
;
int
middle
=
((
int
)
m
.
size
()
+
1
)
/
2
;
for
(
int
i
=
0
;
i
<
middle
;
i
++
)
{
left
.
push_back
(
m
[
i
]);
}
for
(
int
i
=
middle
;
i
<
(
int
)
m
.
size
();
i
++
)
{
right
.
push_back
(
m
[
i
]);
}
left
=
sort_custom
(
left
);
right
=
sort_custom
(
right
);
result
=
merge
(
left
,
right
);
return
result
;
}
\ 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