Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
1
18305R006-18305R009-18305R010-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
RAMEESH PAUL
18305R006-18305R009-18305R010-git
Commits
5041e021
Commit
5041e021
authored
Sep 21, 2018
by
ShahRukh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change implementation to merge-sort
parent
0ea14c1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
15 deletions
+60
-15
main
main
+0
-0
sorting.cpp
sorting.cpp
+60
-15
No files found.
main
View file @
5041e021
No preview for this file type
sorting.cpp
View file @
5041e021
#include<vector>
#include<iostream>
#include"sorting.h"
using
namespace
std
;
using
namespace
std
;
vector
<
int
>
mergeSorting
(
vector
<
int
>
arr
);
vector
<
int
>
mergeSorting
(
vector
<
int
>
v
);
vector
<
int
>
merge
(
vector
<
int
>
first
,
vector
<
int
>
second
){
vector
<
int
>
v
;
int
countFirst
=
0
;
int
countSecond
=
0
;
int
size
=
first
.
size
()
+
second
.
size
();
int
left
=
1
;
for
(
int
i
=
0
;
i
<
size
;
i
++
){
if
(
countFirst
<
first
.
size
()
&&
countSecond
<
second
.
size
()
){
left
=
(
first
[
countFirst
]
<
second
[
countSecond
]);
}
else
if
(
countFirst
<
first
.
size
())
{
left
=
1
;
}
else
{
left
=
0
;
}
if
(
left
==
1
){
v
.
push_back
(
first
[
countFirst
]);
if
(
first
.
size
()
>
countFirst
){
countFirst
+=
1
;
}
}
else
{
v
.
push_back
(
second
[
countSecond
]);
if
(
second
.
size
()
>
countSecond
){
countSecond
+=
1
;
}
}
}
return
v
;
}
vector
<
int
>
mergeSorting
(
vector
<
int
>
v
){
if
(
v
.
size
()
<=
1
){
return
v
;
}
vector
<
int
>
first
(
v
.
cbegin
(),
v
.
cbegin
()
+
(
v
.
size
()
/
2
));
vector
<
int
>
second
(
v
.
cbegin
()
+
(
v
.
size
()
/
2
),
v
.
cend
());
return
merge
(
mergeSorting
(
first
),
mergeSorting
(
second
));
}
vector
<
int
>
sort_custom
(
vector
<
int
>
v
){
vector
<
int
>
sort_custom
(
vector
<
int
>
v
){
int
i
,
j
;
vector
<
int
>
sortVec
=
mergeSorting
(
v
);
int
n
=
v
.
size
();
return
sortVec
;
for
(
i
=
0
;
i
<
n
-
1
;
i
++
){
}
for
(
j
=
0
;
j
<
n
-
i
-
1
;
j
++
){
if
(
v
[
j
]
>
v
[
j
+
1
]){
int
temp
;
temp
=
v
[
j
];
v
[
j
]
=
v
[
j
+
1
];
v
[
j
+
1
]
=
temp
;
}
}
}
return
v
;
}
\ 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