-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLista.cpp
More file actions
65 lines (58 loc) · 1.33 KB
/
Lista.cpp
File metadata and controls
65 lines (58 loc) · 1.33 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Created by kukul on 25.10.2019.
//
#include "Lista.h"
#include <iostream>
using namespace std;
void Lista::insert(int x, int i, elem *&lista) {
elem* nowaLista = new elem;
nowaLista->dane = x;
if (lista==NULL){
nowaLista->nast = NULL;
lista = nowaLista;
}else{
elem* pomocnicza = lista;
for(int j=2;j<i;j++){
pomocnicza = pomocnicza->nast;
}
nowaLista->nast = pomocnicza->nast;
pomocnicza->nast = nowaLista;
}
}
void Lista::remove(int i, elem *&lista) {
elem* pomocnicza = lista;
elem* k;
for (int j = 1; j <= i; ++j) {
pomocnicza = pomocnicza->nast;
if(j==(i-1)){
k = pomocnicza;
}
}
k->nast=pomocnicza->nast;
delete(pomocnicza);
}
int Lista::read(int i, elem *lista) {
elem* pomocnicza = lista;
for (int j = 1; j < i; j++) {
pomocnicza = pomocnicza->nast;
}
int x = pomocnicza->dane;
return x;
}
int Lista::size(elem *lista) {
int i=0;
elem* pomocnicza = lista;
while(pomocnicza!=NULL){
i++;
pomocnicza = pomocnicza->nast;
}
return i;
}
void Lista::print(elem *lista) {
int i = size(lista);
elem* pomocnicza = lista;
for(int j=0;j<i;j++){
cout << pomocnicza->dane << endl;
pomocnicza = pomocnicza->nast;
}
}