Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct stack_node
- {
- int data;
- struct stack_node *next;
- };
- void fill(struct stack_node **n)
- {
- *n = (struct stack_node *)malloc(sizeof(struct stack_node));
- (*n)->next = (struct stack_node *)malloc(sizeof(struct stack_node));
- (*n)->next->next = (struct stack_node *)malloc(sizeof(struct stack_node));
- (*n)->next->next->next = (struct stack_node *)malloc(sizeof(struct stack_node));
- (*n)->next->next->next->next = (struct stack_node *)malloc(sizeof(struct stack_node));
- (*n)->next->next->next->next->next = NULL;
- (*n)->data =0;
- (*n)->next->data = 1;
- (*n)->next->next->data = 2;
- (*n)->next->next->next->data = 3;
- (*n)->next->next->next->next->data = 4;
- }
- struct stack_node *push(struct stack_node *n, int data)
- {
- struct stack_node *new_node = (struct stack_node *)malloc(sizeof(struct stack_node));
- if(new_node)
- {
- new_node->data = data;
- new_node->next = n;
- n = new_node;
- }
- return n;
- }
- void printing(struct stack_node *n)
- {
- while(n)
- {
- printf("%d ", n->data);
- n=n->next;
- }
- }
- int min_element(struct stack_node **n)
- {
- int min=(*n)->data;
- while(*n)
- {
- if(min>(*n)->data)
- {
- min = (*n)->data;
- }
- (*n) = (*n)->next;
- }
- return min;
- }
- int main()
- {
- struct stack_node *n = NULL;
- fill(&n);
- printing(n);
- printf("\nMIN: %d", min_element(&n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement