1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/julia_course.git synced 2024-11-09 13:21:07 +00:00

Add push!, append! and pop!

This commit is contained in:
Mo8it 2022-03-28 02:17:22 +02:00
parent 1e3d07fbb0
commit 55a93ed41e

View file

@ -24,6 +24,8 @@ using Measurements, Unitful
using LinearAlgebra
# ╔═╡ d1a4ef8b-8e7d-4d34-80d8-cee195e237ae
# Oh, no, you found my secret! 😱
# Don't change this hidden cell!
begin
using PlutoUI
@ -831,6 +833,43 @@ begin
second_vector
end
# ╔═╡ 1fd6fdd3-82a0-480e-9db6-e657536da63f
# Add elements to a vector
begin
growing_vector = []
push!(growing_vector, 42)
push!(growing_vector, 33)
growing_vector
end
# ╔═╡ ace6fd59-ccb8-4318-85ce-966b04c4ce53
# Append elements of one vector to another one
begin
growing_vector2 = [1, 2]
vector_to_append = [22, 33, 44]
append!(growing_vector2, vector_to_append)
growing_vector2
end
# ╔═╡ b7bb3e82-a2ee-4356-8c7b-0db664adcbe0
# Remove elements
begin
shrinking_vector = [-1, -2, -2, 55, 123, 44, 52, 98, -3, -112]
@show shrinking_vector
# Remove the last element
pop!(shrinking_vector)
@show shrinking_vector
# Remove the first element
popfirst!(shrinking_vector)
@show shrinking_vector
# Remove at a given index
popat!(shrinking_vector, 3)
@show shrinking_vector
end
# ╔═╡ 027313d6-c247-43e9-872b-c3f0fe71b733
third_vector = [1, 2, 3]
@ -1483,6 +1522,9 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═628852dc-16e5-4a03-93a9-be209b1e8fb4
# ╟─3ea54f0d-2aa5-47a3-bbc3-92023a56b834
# ╠═e9e117af-1194-4d64-94a8-3e9fd51498aa
# ╠═1fd6fdd3-82a0-480e-9db6-e657536da63f
# ╠═ace6fd59-ccb8-4318-85ce-966b04c4ce53
# ╠═b7bb3e82-a2ee-4356-8c7b-0db664adcbe0
# ╠═027313d6-c247-43e9-872b-c3f0fe71b733
# ╠═e77e7ceb-31e3-4231-9923-f62b1382a2d1
# ╠═65d3ddc2-36ed-4126-9211-e838ffc0d859