Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct stack_struct {
- int data;
- struct stack_struct *next;
- } stack_s;
- void push(stack_s **head, int data) {
- stack_s *tmp = malloc(sizeof(stack_s));
- //printf("%d \n", head);
- tmp->next = *head;
- tmp->data = data;
- *head = tmp;
- //printf("%d \n", head);
- }
- int pop(stack_s **head) {
- stack_s *last;
- int data;
- if (*head == NULL) return 1;
- last = *head;
- *head = (*head)->next;
- data = last->data;
- free(last);
- return data;
- }
- void printStack(stack_s *head) {
- printf("stack >");
- while (head) {
- printf("%d ", head->data);
- head = head->next;
- }
- }
- int main(){
- stack_s *head = NULL;
- stack_s *tmp;
- for (int i = 0; i < 300; i++) push(&head, i);
- printStack(head);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement