SHARE
TWEET

링크드리스트헤더

RedWarden Sep 15th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2. #ifndef LIST_H
  3. #define LIST_H
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. typedef int element;
  8. typedef struct StackNode {
  9.     element data;
  10.     struct StackNode* link;
  11. }StackNode;
  12.  
  13. typedef struct {
  14.     StackNode* top;
  15. }LinkedStack;
  16.  
  17. void init(LinkedStack* s) {
  18.     s->top = NULL;
  19. }
  20. int is_empty(LinkedStack* s) {
  21.     return (s->top == NULL);
  22. }
  23. void push(LinkedStack* s, element item) {
  24.     StackNode* temp = (StackNode*)malloc(sizeof(StackNode));
  25.     temp->data = item;
  26.     temp->link = s->top;
  27.     s->top = temp;
  28. }  
  29. element pop(LinkedStack* s) {
  30.     int data;
  31.     if (is_empty(s)) {
  32.         fprintf(stderr, "파일이 비어있음\n");
  33.         exit(1);
  34.     }
  35.     else {
  36.         StackNode* temp = s->top;
  37.         data = temp->data;
  38.         s->top = s->top -> link;
  39.         free(temp);
  40.         return data;
  41.     }
  42. }
  43. void print_stack(LinkedStack* s) {
  44.     for (StackNode* p = s->top; p != NULL; p = p->link)
  45.     {
  46.         printf("%d->", p->data);
  47.     }
  48.     printf("NULL\n");
  49. }
  50.  
  51. #endif // !LIST_H
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top