FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm-examples/cpp-algorithm/src/array/delete_element.cpp at main · codejsha/algorithm-examples · GitHub
codejsha
/
algorithm-examples
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm-examples
/
cpp-algorithm
/
src
/
array
/
delete_element.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (38 loc) · 1023 Bytes
Breadcrumbs
algorithm-examples
/
cpp-algorithm
/
src
/
array
/
delete_element.cpp
Copy path
File metadata and controls
47 lines (38 loc) · 1023 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
include
"
delete_element.h
"
#
include
<
algorithm
>
auto
DeleteElement::DeleteDuplicates
(std::vector<
int
>& numbers) -> std::vector<int>
{
if
(numbers.
empty
())
{
return
{};
}
int
write_index =
1
;
for
(
int
i =
1
; i <
static_cast
<
int
>(numbers.
size
()); ++i)
{
if
(numbers[write_index -
1
] != numbers[i])
{
numbers[write_index] = numbers[i];
++write_index;
}
}
return
std::vector<
int
>{numbers.
begin
(), numbers.
begin
() + write_index};
}
auto
DeleteElement::DeleteDuplicateElements
(std::vector<
int
>& numbers) -> std::vector<int>
{
if
(numbers.
empty
())
{
return
{};
}
std::ranges::sort
(numbers);
numbers.
erase
(
std::ranges::unique
(numbers).
begin
(), numbers.
end
());
return
numbers;
}
auto
DeleteElement::DeleteSpecificElements
(std::vector<
int
>& numbers,
const
int
element) -> std::vector<int>
{
if
(numbers.
empty
())
{
return
{};
}
std::erase
(numbers, element);
return
numbers;
}
Back
|
FazBrowse Home
|
New Git URL