Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dynamic_vectors
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PREMIERE
PROG_SEQ
dynamic_vectors
Commits
9d853de0
Commit
9d853de0
authored
3 years ago
by
abivarma.kandiah
Browse files
Options
Downloads
Patches
Plain Diff
Add vector remove
parent
c59f139c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
header/vectors.h
+1
-0
1 addition, 0 deletions
header/vectors.h
src/test_vectors.c
+14
-3
14 additions, 3 deletions
src/test_vectors.c
src/vectors.c
+16
-0
16 additions, 0 deletions
src/vectors.c
with
31 additions
and
3 deletions
header/vectors.h
+
1
−
0
View file @
9d853de0
...
@@ -25,5 +25,6 @@ void vector_push(vector vec, type element);
...
@@ -25,5 +25,6 @@ void vector_push(vector vec, type element);
type
vector_pop
(
vector
vec
);
type
vector_pop
(
vector
vec
);
void
vector_set
(
vector
vec
,
int
index
,
type
element
);
void
vector_set
(
vector
vec
,
int
index
,
type
element
);
type
vector_get
(
vector
vec
,
int
index
);
type
vector_get
(
vector
vec
,
int
index
);
type
vector_remove
(
vector
vec
,
int
index
);
#endif
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/test_vectors.c
+
14
−
3
View file @
9d853de0
...
@@ -12,23 +12,34 @@
...
@@ -12,23 +12,34 @@
int
main
()
int
main
()
{
{
//Test Vector create
vector
test
=
vector_create
();
vector
test
=
vector_create
();
printf
(
"Created Vector lenght : %d
\n
"
,
vector_length
(
test
));
printf
(
"Created Vector lenght : %d
\n
"
,
vector_length
(
test
));
//Test Vector push
vector_push
(
test
,
15
);
vector_push
(
test
,
15
);
printf
(
"Modified Vector lenght : %d
\n
"
,
vector_length
(
test
));
printf
(
"Modified Vector lenght : %d
\n
"
,
vector_length
(
test
));
//Test Vector pop
type
val
=
vector_pop
(
test
);
type
val
=
vector_pop
(
test
);
printf
(
"Modified Vector lenght : %d and the value we popped : %d
\n
"
,
vector_length
(
test
),
val
);
printf
(
"Modified Vector lenght : %d and the value we popped : %d
\n
"
,
vector_length
(
test
),
val
);
//Test Vector set and get
vector_push
(
test
,
42
);
vector_push
(
test
,
42
);
vector_set
(
test
,
0
,
69
);
vector_set
(
test
,
0
,
69
);
val
=
vector_get
(
test
,
0
);
val
=
vector_get
(
test
,
0
);
printf
(
"Modified Vector lenght : %d and the value we setted : %d
\n
"
,
vector_length
(
test
),
val
);
printf
(
"Modified Vector lenght : %d and the value we setted : %d
\n
"
,
vector_length
(
test
),
val
);
val
=
vector_pop
(
test
);
//Test Vector remove
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
vector_push
(
test
,
i
);
}
printf
(
"Value at index 3 : %d
\n
"
,
vector_get
(
test
,
3
));
vector_remove
(
test
,
3
);
printf
(
"New Value at index 3 : %d
\n
"
,
vector_get
(
test
,
3
));
...
...
This diff is collapsed.
Click to expand it.
src/vectors.c
+
16
−
0
View file @
9d853de0
...
@@ -78,3 +78,19 @@ type vector_get(vector vec, int index)
...
@@ -78,3 +78,19 @@ type vector_get(vector vec, int index)
return
vec
->
content
[
index
];
return
vec
->
content
[
index
];
}
}
type
vector_remove
(
vector
vec
,
int
index
)
{
assert
(
index
<
vec
->
length
);
type
tmp
=
vec
->
content
[
index
];
vec
->
length
--
;
for
(
int
i
=
index
;
i
<
vec
->
length
;
i
++
)
// Ex : 0 1 2 {3} 4 5 // Index 3 , lenght 6
{
vec
->
content
[
i
]
=
vec
->
content
[
i
+
1
];
}
return
tmp
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment