Question: pl ans soon Task 2: Stack In this program (https:/www.onlinegdb.com/Was/32633), you need to complete these functions: 1. peak(); return the top of the element in

pl ans soon  pl ans soon Task 2: Stack In this program (https:/www.onlinegdb.com/Was/32633), you
need to complete these functions: 1. peak(); return the top of the
element in the stack; return 0 and print out an error if
stack is empty; (You can not use popping function) 2. popdup(): duplicate
the top element in the stack; 3. popswap(): swap the top two
elements in the stack; 4. clear(): clear the stack; You can add
code in main function to test your functions but please don't touch

Task 2: Stack In this program (https:/www.onlinegdb.com/Was/32633), you need to complete these functions: 1. peak(); return the top of the element in the stack; return 0 and print out an error if stack is empty; (You can not use popping function) 2. popdup(): duplicate the top element in the stack; 3. popswap(): swap the top two elements in the stack; 4. clear(): clear the stack; You can add code in main function to test your functions but please don't touch other parts of the code. 1 include 2 #include 3 4 #define MAXOP 100 5 #define NUMBER OF 6 7 int getop(char 0); 8 void push (double); 9 double pop(void); 10 double peak(); 11 void popdup(); 12 void popswap(); 13 void clear(); 14 15 int main() 16- { 17 int type; 18 double op2; 19 char s[MAXOP]; 20 21 22 //test new functions 23 push(10); 24 push(11); 25 printf("peak:\t%f ", peak()); 26 printf("peak:\t%f ", peak()); 27 popswap(); 28 printf("popswap(), peak:\t%f ", peak()); 29 popdup(); popdup(); for (int k=0; k0) 83 return valc--sp]; 84 - 83 return val[--sp]; else{ 85 printf("error: stack empty "); 86 return 0.6; 87 } 88 } 89 90- 91 // returns the top of the stack 92 - double peakO{ 93 // YOUR CODE HERE 94 return 0.0; 95 } 96 97 // duplicate the element at the top of the stack, at the top of the stack 98 - void popdupO{ 99 // YOUR CODE HERE 100 return; 101 } 102 103 // swap the top two elements of the stack 104 - void popswap({ 105 // YOUR CODE HERE 106 return; 107 } 108 109. void clear(){ 110 // YOUR CODE HERE 111 return 112 } 113 - ********/ 114 115 #include 116 117 int getch(void); 118 void ungetch(int); 119 120 /* gets the next operator or operand */ 121 - int getop(char so){ 122 int i, c; 123 124 while( (s[0] = C = getch() ''Il C == '\t") 125 ; 126 s[1]='\0'; 127 if(!isdigit(C) && c != '.') 128 return c; 129 i = 0; 130 if(isdigit(c)) 131 while (isdigit(s[++i) = C = getch())) 132 3 133 if (c == '.') 134 while (isdigit(s[++i] = C = getch()) 135 136 s[i] = '\0'; 137 if (c != EOF) 138 ungetch(c); 139 return NUMBER; 2 o' 140 140 } 141 142 #define BUFSIZE 100 143 144 char buf(BUFSIZE]; 145 int bufp=0; 146 get the next character, either from standard input or 147 from the buffer (of character's that we placed 'back on the buffer) 148 */ 149 int getch(void){ 150 return (bufp > 0) ? buf(--bufp] : getchar(); 151 } 152 153 - /*populate the local buffer with characters you meant to 'put back' b/c you 154 read too far*/ 155 void ungetch(int c){ 156 if (bufp >= BUFSIZE) 157 printf("ungetch: too many characters "); 158 else 159 buf[bufp+] = c; 160 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!