Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wektor_cpp
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
wektor_cpp
Commits
88f2cbc7
Commit
88f2cbc7
authored
Apr 28, 2026
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tablica dynamiczna: new i delete
parent
341f8685
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
wektor.cpp
wektor.cpp
+20
-6
wektor.h
wektor.h
+5
-2
No files found.
wektor.cpp
View file @
88f2cbc7
#include <iostream>
#include "wektor.h"
const
int
startowy_rozmiar_tablicy
=
8
;
Wektor
::
Wektor
()
:
liczba_elementow
{
0
}
{}
:
rozmiar_tablicy
{
startowy_rozmiar_tablicy
},
liczba_elementow
{
0
}
{
t
=
new
int
[
rozmiar_tablicy
];
}
Wektor
::~
Wektor
()
{
delete
[]
t
;
}
int
Wektor
::
size
()
{
int
Wektor
::
size
()
const
{
return
liczba_elementow
;
}
void
Wektor
::
push_back
(
int
e
)
{
t
[
liczba_elementow
]
=
e
;
liczba_elementow
++
;
if
(
liczba_elementow
==
rozmiar_tablicy
)
{
// przerzuć elementy do większej tablicy
rozmiar_tablicy
=
2
*
rozmiar_tablicy
;
int
*
nt
=
new
int
[
rozmiar_tablicy
];
for
(
int
i
=
0
;
i
<
liczba_elementow
;
i
++
)
{
nt
[
i
]
=
t
[
i
];
}
delete
[]
t
;
t
=
nt
;
// do t wpisujemy wskaźnik do nowe tablicy
}
t
[
liczba_elementow
++
]
=
e
;
}
void
Wektor
::
set
(
int
idx
,
int
e
)
{
...
...
wektor.h
View file @
88f2cbc7
...
...
@@ -5,7 +5,10 @@
/** Tablica zmiennej długości zawierająca wartości int. */
class
Wektor
{
int
t
[
10
];
int
*
t
;
// fizyczny rozmiar wewnętrznej tablicy
int
rozmiar_tablicy
;
// logiczny rozmiar wektora = ile pozycji w tablicy jest zajętych = indeks pierwszej wolnej pozycji
int
liczba_elementow
;
...
...
@@ -15,7 +18,7 @@ public:
~
Wektor
();
int
size
();
int
size
()
const
;
/** Dodanie nowego elementu na końcu. */
void
push_back
(
int
e
);
...
...
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