Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
1
170050002-170050022-170050060-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
MASHKARIA SATVIK MEHULBHAI
170050002-170050022-170050060-git
Commits
d44604ac
Commit
d44604ac
authored
Aug 26, 2018
by
ARPIT AGGARWAL
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed implementation to merge-sort
parent
feba6dea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
9 deletions
+64
-9
sorting.cpp
sorting.cpp
+64
-9
No files found.
sorting.cpp
View file @
d44604ac
#include "sorting.h"
using
namespace
std
;
void
merge
(
int
arr
[],
int
l
,
int
m
,
int
r
)
{
int
i
,
j
,
k
;
int
n1
=
m
-
l
+
1
;
int
n2
=
r
-
m
;
int
L
[
n1
],
R
[
n2
];
for
(
i
=
0
;
i
<
n1
;
i
++
)
L
[
i
]
=
arr
[
l
+
i
];
for
(
j
=
0
;
j
<
n2
;
j
++
)
R
[
j
]
=
arr
[
m
+
1
+
j
];
i
=
0
;
j
=
0
;
k
=
l
;
while
(
i
<
n1
&&
j
<
n2
)
{
if
(
L
[
i
]
<=
R
[
j
])
{
arr
[
k
]
=
L
[
i
];
i
++
;
}
else
{
arr
[
k
]
=
R
[
j
];
j
++
;
}
k
++
;
}
while
(
i
<
n1
)
{
arr
[
k
]
=
L
[
i
];
i
++
;
k
++
;
}
while
(
j
<
n2
)
{
arr
[
k
]
=
R
[
j
];
j
++
;
k
++
;
}
}
void
mergeSort
(
int
arr
[],
int
l
,
int
r
)
{
if
(
l
<
r
)
{
int
m
=
l
+
(
r
-
l
)
/
2
;
mergeSort
(
arr
,
l
,
m
);
mergeSort
(
arr
,
m
+
1
,
r
);
merge
(
arr
,
l
,
m
,
r
);
}
}
vector
<
int
>
sort_custom
(
vector
<
int
>
data
)
{
vector
<
int
>
arr
(
data
.
begin
(),
data
.
end
())
;
for
(
int
i
=
0
;
i
<
data
.
size
();
i
++
)
{
for
(
int
j
=
0
;
j
<
data
.
size
()
-
i
-
1
;
j
++
)
{
if
(
arr
[
j
]
>
arr
[
j
+
1
])
swap
(
arr
[
j
],
arr
[
j
+
1
])
;
}
}
return
arr
;
//vector<int> arr(data.begin(), data.end()) ;
int
n
=
data
.
size
()
;
int
arr
[
n
]
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
arr
[
i
]
=
data
[
i
]
;
}
mergeSort
(
arr
,
0
,
n
-
1
)
;
vector
<
int
>
res
(
arr
,
arr
+
n
)
;
return
res
;
}
\ 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