Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define bool int
- #define true 1
- #define false 0
- /*stos definiowanie*/
- /*#####################################################################*/
- typedef struct stos{
- int value;
- struct stos *next;
- } stos;
- stos *stos_create(int value)
- {
- stos *s = malloc(sizeof(stos));
- s-> value = value;
- s-> next = NULL;
- }
- bool stos_is_empty(stos *s)
- {
- if(s == NULL) return true;
- return false;
- }
- int stos_last(stos *s)
- {
- int output = -1;
- while(s){
- output = s-> value;
- s = s -> next;
- }
- return output;
- }
- void stos_add_value(stos *s, int value)
- {
- stos *start = s;
- stos *end = stos_create(value);
- while(s-> next != NULL){
- s = s -> next;
- }
- s->next = end;
- s = start;
- }
- void stos_withdraw(stos *s)
- {
- if(stos_is_empty(s) == false){
- while(s->next != NULL) s = s->next;
- free(s);
- }
- }
- void stos_release(stos *s)
- {
- stos *help_stos = s;
- if(stos_is_empty(s)){
- while(s){
- help_stos = s->next;
- free(s);
- s = help_stos;
- }
- }
- }
- void show_stos(stos *s)
- {
- printf("stos starts:\n");
- while(s){
- printf("%d ",s->value);
- s = s->next;
- }
- printf("\nstos ends\n");
- }
- /*#######################################################################*/
- /*stos_testowanie*/
- int main(void)
- {
- stos *s = stos_create(7);
- stos_add_value(s, 8);
- show_stos(s);
- stos_add_value(s, 8989);
- printf("ostatni: %d\n", stos_last(s));
- show_stos(s);
- stos_withdraw(s);
- printf("ostatni: %d\n", stos_last(s));
- show_stos(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement