-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzad2jc.cpp
64 lines (55 loc) · 998 Bytes
/
zad2jc.cpp
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
64
#include<stdio.h>
#include<stdlib.h>
typedef struct _node {
int val;
struct _node *next;
} node;
typedef node* lista;
lista push(int val, lista l){
lista nowy = (node*)malloc(sizeof(node));
nowy->val = val;
nowy->next = l;
return nowy;
}
int top(lista l){
if(l) return l->val;
return 0;
}
lista pop(lista l){
lista nowy = NULL;
if(l){
nowy = l->next;
free(l);
}
return nowy;
}
void printList(lista l){
int i = 0;
while(l && i++ < 8){
printf("%i ", l->val);
l = l->next;
}
printf("\n\n");
}
void zcykluj(lista l){
if(l){
lista prev = NULL, nast, first = l;
while(l){
nast = l->next;
l->next = prev;
prev = l;
l = nast;
}
first->next = prev;
}
}
int main(){
lista l = NULL;
l = push(1, l);
l = push(2, l);
l = push(3, l);
l = push(4, l);
zcykluj(l);
printList(l);
return 0;
}