Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /* This is a template with the functions you must implement for this assignment.
  4. *
  5. * Note that you are free to implement any additional function you consider appropriate.
  6. *
  7. */
  8. struct stack_value{
  9. char value;
  10. struct stack_value *next;
  11. };
  12. struct stack_value *Head = NULL;
  13.  
  14.  
  15. // push a character into the stack
  16. void stack_push(char c){
  17. printf("beginning\n");
  18. struct stack_value *temp = malloc(sizeof(struct stack_value));
  19.  
  20. temp->value = c;
  21. temp->next = Head;
  22. Head = temp;
  23. printf("%i\n",c );
  24. printf("end\n");
  25. }
  26.  
  27. /* Overwrites the character pointed by c with the character currently on
  28. * top of the stack.
  29. *
  30. * The function returns 0 if the operation can be carried out successfully,
  31. * and any non-zero number if the operation could not be performed (for instance
  32. * because the stack is empty).
  33. */
  34. int stack_top(char *c){
  35. if(Head == NULL)
  36. return 1;
  37.  
  38. else{
  39. *c = (Head->next)->value;
  40. printf("%i\n",*c );
  41. return 0;
  42. }
  43. }
  44.  
  45.  
  46. /* Overwrites the character pointed by c with the character currently on
  47. * top of the stack, and removes the character from the top of the stack.
  48. *
  49. * The function returns 0 if the operation can be carried out successfully,
  50. * and any non-zero number if the operation could not be performed (for instance
  51. * because the stack is empty).
  52. */
  53. int stack_pop(char *c){
  54. if(Head == NULL)
  55. return 1;
  56.  
  57. *c = (Head->next)->value;
  58. struct stack_value *temp;
  59. temp = Head;
  60. Head = Head->next;
  61. return 0;
  62. }
  63.  
  64.  
  65.  
  66. /* Returns a dynamically allocated string (in the heap)
  67. * containing the characters in the string pointed by source,
  68. * excluding any one-line comment.
  69. */
  70. char *remove_single_line_comment(const char *source){}
  71.  
  72.  
  73. /* Returns a dynamically allocated string (in the heap)
  74. * containing the characters in the string pointed by source,
  75. * excluding any multi-line comment.
  76. */
  77. char *remove_multi_line_comment(const char *source){}
  78.  
  79.  
  80. /* The main function of your program. Rename into mymain
  81. * for testing.
  82. */
  83. int mymain(int argc, char **argv) {
  84.  
  85. //the code of your main function goes here.
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement