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
f544005f
Commit
f544005f
authored
Sep 23, 2018
by
DIPTYAROOP MAJI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change implementation to insertion-sort
parent
b1e0aaa8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
57 deletions
+31
-57
a.out
a.out
+0
-0
main.cpp
main.cpp
+3
-2
sorting.cpp
sorting.cpp
+26
-14
sorting.cpp~
sorting.cpp~
+0
-40
sorting.h
sorting.h
+2
-1
No files found.
a.out
100644 → 100755
View file @
f544005f
No preview for this file type
main.cpp
View file @
f544005f
...
...
@@ -4,7 +4,8 @@
using
namespace
std
;
void
bubbleSort
(
vector
<
int
>&
a
);
//void bubbleSort(vector<int>& a);
vector
<
int
>
sort_custom
(
vector
<
int
>
arr
);
void
printVector
(
vector
<
int
>
a
);
...
...
@@ -20,7 +21,7 @@ int main(int argc, char const *argv[])
a
.
push_back
(
num
);
}
//printVector(a);
bubbleSort
(
a
);
a
=
sort_custom
(
a
);
printVector
(
a
);
...
...
sorting.cpp
View file @
f544005f
#include <vector>
#include "sorting.h"
using
namespace
std
;
#include <vector>
v
oid
bubbleSort
(
vector
<
int
>&
a
)
v
ector
<
int
>
sort_custom
(
const
vector
<
int
>
arr
)
{
bool
swapp
=
true
;
while
(
swapp
){
swapp
=
false
;
for
(
size_t
i
=
0
;
i
<
a
.
size
()
-
1
;
i
++
)
{
if
(
a
[
i
]
>
a
[
i
+
1
]
){
a
[
i
]
+=
a
[
i
+
1
];
a
[
i
+
1
]
=
a
[
i
]
-
a
[
i
+
1
];
a
[
i
]
-=
a
[
i
+
1
];
swapp
=
true
;
}
unsigned
int
i
,
j
;
vector
<
int
>
sortedArray
(
arr
.
size
());
sortedArray
=
arr
;
int
max
;
for
(
i
=
0
;
i
<
arr
.
size
();
i
++
){
//max = arr[i];
for
(
j
=
i
;
j
<
arr
.
size
();
j
++
){
if
(
sortedArray
[
i
]
>
sortedArray
[
j
]){
int
tmp
;
tmp
=
sortedArray
[
i
];
sortedArray
[
i
]
=
sortedArray
[
j
];
sortedArray
[
j
]
=
tmp
;
}
}
}
// return a;
return
sortedArray
;
}
sorting.cpp~
deleted
100644 → 0
View file @
b1e0aaa8
#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 @
f544005f
using
namespace
std
;
void
bubbleSort
(
vector
<
int
>&
a
);
//
void bubbleSort(vector<int>& a);
void
printVector
(
vector
<
int
>
a
);
vector
<
int
>
sort_custom
(
vector
<
int
>
arr
);
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