Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- // 4.6
- typedef struct {
- int *tab;
- int capacitate;
- int index;
- }Vector;
- Vector create(){
- Vector t;
- t.capacitate = 2;
- t.index = 0;
- t.tab = (int*)malloc(sizeof(int) * t.capacitate);
- return t;
- }
- void add(Vector t, int element){
- //Caz 1, indexul este sub capacitate
- if (t.index < t.capacitate){
- t.tab[t.index] = element;
- t.index++;
- }
- }
- int main() {
- Vector v = create();
- add(v, 10);
- add(v, 20);
- // add(v, 30);
- // add(v, 40);
- // for (int i = 0; i < v.index;i++){
- // printf("tab[%2d] = %d\n", i, get(v, i));
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement