Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
Q
quick_sort_cpp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
quick_sort_cpp
Commits
7350926d
Commit
7350926d
authored
Mar 16, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parents
Pipeline
#1949
failed with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
0 deletions
+69
-0
.gitignore
.gitignore
+2
-0
main.cpp
main.cpp
+23
-0
sorting.h
sorting.h
+44
-0
No files found.
.gitignore
0 → 100644
View file @
7350926d
/main
\ No newline at end of file
main.cpp
0 → 100644
View file @
7350926d
#include <iostream>
#include <vector>
#include "sorting.h"
#define E6 1000000;
#define E7 10000000;
#define E8 100000000;
#define U8 256;
int
ARR_LEN
=
E6
;
int
main
()
{
ARR_LEN
=
ARR_LEN
*
2
;
vector
<
int
>
arr
(
ARR_LEN
,
0
);
for
(
int
i
=
0
;
i
<
ARR_LEN
;
i
++
)
{
// arr[i] = rand() % 4294967295;
arr
[
i
]
=
rand
()
%
256
;
}
quick_sort
(
arr
);
return
0
;
}
\ No newline at end of file
sorting.h
0 → 100644
View file @
7350926d
#include <vector>
using
namespace
std
;
void
quick_sort_node
(
vector
<
int
>
&
arr
,
int
st
,
int
ed
,
vector
<
int
>
&
worker
)
{
int
k
=
st
-
1
;
int
tmp
;
for
(
int
i
=
st
;
i
<
ed
;
i
++
)
{
if
(
arr
[
i
]
<=
arr
[
ed
-
1
])
{
k
+=
1
;
tmp
=
arr
[
i
];
arr
[
i
]
=
arr
[
k
];
arr
[
k
]
=
tmp
;
}
}
int
len2
=
ed
-
k
-
1
;
if
(
k
>
1
)
{
worker
.
push_back
(
st
);
worker
.
push_back
(
k
);
}
if
(
len2
>
1
)
{
worker
.
push_back
(
k
+
1
);
worker
.
push_back
(
ed
);
}
}
void
quick_sort_linear
(
vector
<
int
>
&
arr
,
vector
<
int
>
&
worker
)
{
while
(
worker
.
size
())
{
int
w2
=
worker
[
worker
.
size
()
-
1
];
worker
.
pop_back
();
int
w1
=
worker
[
worker
.
size
()
-
1
];
worker
.
pop_back
();
if
(
w1
==
w2
)
continue
;
quick_sort_node
(
arr
,
w1
,
w2
,
worker
);
}
}
void
quick_sort
(
vector
<
int
>
&
arr
)
{
vector
<
int
>
worker
;
worker
.
push_back
(
0
);
worker
.
push_back
(
arr
.
size
());
quick_sort_linear
(
arr
,
worker
);
}
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