Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
1
173050031-183050016-183050011-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
KSHITIJ SINGHA
173050031-183050016-183050011-git
Commits
ebe6a3b5
Commit
ebe6a3b5
authored
Sep 23, 2018
by
KSHITIJ SINGHA
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'merge-sort'
Conflicts: Makefile a.out main.cpp sorting.cpp sorting.h
parents
58ca7897
e75ce9e4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
49 deletions
+87
-49
Makefile
Makefile
+16
-0
main.cpp
main.cpp
+11
-9
sorting.cpp
sorting.cpp
+56
-0
sorting.cpp~
sorting.cpp~
+0
-40
sorting.h
sorting.h
+4
-0
No files found.
Makefile
View file @
ebe6a3b5
<<<<<<<
HEAD
all
:
hello
hello
:
main.o sorting.o
...
...
@@ -12,3 +13,18 @@ sorting.o: sorting.cpp
clean
:
rm
-rf
a.out
=======
CC
=
g++
all
:
main.o sorting.o
g++ main.o sorting.o
-o
main
main.o
:
main.cpp sorting.h
g++
-I
.
-c
main.cpp
sorting.o
:
sorting.cpp sorting.h
g++
-I
.
-c
sorting.cpp
clean
:
rm
-rf
*
.o
>>>>>>>
merge-sort
main.cpp
View file @
ebe6a3b5
...
...
@@ -3,34 +3,36 @@
#include "sorting.h"
using
namespace
std
;
<<<<<<<
HEAD
vector
<
int
>
sort_custom
(
vector
<
int
>&
a
);
void
printVector
(
vector
<
int
>
a
);
=======
vector
<
int
>
sort_custom
(
vector
<
int
>
);
>>>>>>>
merge
-
sort
int
main
(
int
argc
,
char
const
*
argv
[])
{
vector
<
int
>
a
;
int
num
=
0
;
while
(
num
!=
-
1
)
{
std
::
cin
>>
num
;
if
(
num
!=
-
1
)
//add elements to the vector container
a
.
push_back
(
num
);
}
<<<<<<<
HEAD
//printVector(a);
a
=
sort_custom
(
a
);
=======
>>>>>>>
merge
-
sort
printVector
(
a
);
}
void
printVector
(
vector
<
int
>
a
)
{
a
=
sort_custom
(
a
);
for
(
int
i
=
0
;
i
<
a
.
size
();
i
++
)
{
cout
<<
a
[
i
]
<<
" "
;
}
}
sorting.cpp
View file @
ebe6a3b5
<<<<<<<
HEAD
#include <vector>
#include "sorting.h"
using
namespace
std
;
...
...
@@ -16,4 +17,59 @@ vector<int> sort_custom(const vector<int>& a)
}
}
return
a
;
=======
#include <iostream>
#include <vector>
using
namespace
std
;
vector
<
int
>
merge
(
vector
<
int
>
left
,
vector
<
int
>
right
)
{
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
());
}
}
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
result
;
>>>>>>>
merge
-
sort
}
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
;
}
sorting.cpp~
deleted
100644 → 0
View file @
58ca7897
#include <stdio.h>
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)
// Last i elements are already in place
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}
/* Function to print an array */
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf("n");
}
// Driver program to test above functions
int main()
{
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr)/sizeof(arr[0]);
bubbleSort(arr, n);
printf("Sorted array: \n");
printArray(arr, n);
return 0;
}
sorting.h
View file @
ebe6a3b5
using
namespace
std
;
<<<<<<<
HEAD
vector
<
int
>
sort_custom
(
vector
<
int
>&
a
);
void
printVector
(
vector
<
int
>
a
);
=======
vector
<
int
>
sort_custom
(
vector
<
int
>
);
>>>>>>>
merge
-
sort
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