Give a way to insert asterisks in the sequence FENERBAHCE so that the sequence of values returned by the pop operations is a) EAEE /***** * Stack's Push/Pop operations /= 1D-array implementation of stack structure / 会 #include b) EEAE ******s *****/ %23 特 C code #include

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
C programming
am uu dod supau xuaism un nun SunIou on supƏUI UEIOSUOJ E DUE USNd sueau JƏMOA Y
sequence.
E AS*Y* QUE **STIO *N*
Give the sequence of values returned by the pop operations (see C code below).
Solution: The appearance of the first asterisk symbol (input sequence is șcanned from
left to right) means that the preceding it character A is popped. Afterwards second
appearing asterisk forces E to be popped. Following two characters U and E are pushed
onto the stack (E is currently on the top), while two sequential asterisks result in
repeating pop operation two times, ie. E, and U are popped. Similar observations lead us
to the solution: the sequence of values returned by pôp operations is
AEEUO I.
Give a way to insert asterisks in the sequence FENERBAHCE so that the sequence
of values returned by the pop operations is
a) EAEE
/****** ************* ********************** *********/
/* Stack's Push/Pop operations -
/* 1D-array implementation of stack structure
/ 会分会经 经 会会会 出 经会 合 持
b) EEAE
C code
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
typedef struct
char home[35];
int top;
} My_stack;
void push (My_stack *, char); /* prototypes (declarations) of functions in use */
void pop (My_stack *);
int is empty (My_stack *);
/* they implement standard operations on stack */
void main(void)
My_stack st;
char input[50]; /* input sequence for processing */
int i = 0;
st.top = -1;
/* previous assignment indicates that stack is empty from the beginning */
printf("Enter the sequence (length is limited!): ");
gets(input);
printf("RESULT (after performing pop operation): ");
while(input[i] != '\0') /* while end of line is not reached */
if(isalpha(input[i]))
push(& st, input[i]); /* push character onto the stack */
else
if(input[i] = = )
pop(&st);
Transcribed Image Text:am uu dod supau xuaism un nun SunIou on supƏUI UEIOSUOJ E DUE USNd sueau JƏMOA Y sequence. E AS*Y* QUE **STIO *N* Give the sequence of values returned by the pop operations (see C code below). Solution: The appearance of the first asterisk symbol (input sequence is șcanned from left to right) means that the preceding it character A is popped. Afterwards second appearing asterisk forces E to be popped. Following two characters U and E are pushed onto the stack (E is currently on the top), while two sequential asterisks result in repeating pop operation two times, ie. E, and U are popped. Similar observations lead us to the solution: the sequence of values returned by pôp operations is AEEUO I. Give a way to insert asterisks in the sequence FENERBAHCE so that the sequence of values returned by the pop operations is a) EAEE /****** ************* ********************** *********/ /* Stack's Push/Pop operations - /* 1D-array implementation of stack structure / 会分会经 经 会会会 出 经会 合 持 b) EEAE C code #include<stdio.h> #include<stdlib.h> #include<ctype.h> typedef struct char home[35]; int top; } My_stack; void push (My_stack *, char); /* prototypes (declarations) of functions in use */ void pop (My_stack *); int is empty (My_stack *); /* they implement standard operations on stack */ void main(void) My_stack st; char input[50]; /* input sequence for processing */ int i = 0; st.top = -1; /* previous assignment indicates that stack is empty from the beginning */ printf("Enter the sequence (length is limited!): "); gets(input); printf("RESULT (after performing pop operation): "); while(input[i] != '\0') /* while end of line is not reached */ if(isalpha(input[i])) push(& st, input[i]); /* push character onto the stack */ else if(input[i] = = ) pop(&st);
else
printf("ERROR: Wrong input symbol - program"
" terminates! \n");
exit(1);
i++;
void push(My_stack * s, char c) // push (insert) operation
{ // assume there is enough space for pushing next element!
s -> top ++;
s-> home[s -> top] = c;
void pop(My_stack * s) // pop (remove) operation
if(is_empty(s))
printf("ERROR: Nothing to pop - program terminates\n");
exit(1);
}
printf("%c", s -> home[s -> top -]);
int is_empty(My_stack * s) // checking whether stack is empty or not
return(s -> top < 0?1:0); Result of a sample run (CodeWarrior C/C++ 9.2, OS Windows XP)
Process terminated. Press any key to c lose window.
Enter the sequence (length is limited!>: EAS*Y *QUE***ST*** I0*N***
RESULT (after perforning pop operation>: SYEUQTSAONIE
Note: Remember that «a stack is a list in which nodes can be added only at one end. Nodes can be
accessed or removed only from that same end. When a new node is added it hides the previous end node,
so in order to access that previous node the new node must first be removed. That is, the list works in a
Last-In First-Out (LIFO) manner. The most recently added node is the first available for use, while the
first node added is the last one available for use.
By implementing the stack as an array you have a fixed limit on its size. And while you could obtain the
array at runtime using malloc (), it still might be useful to have a more general solution.
«There are tvwo kinds of facilities <in C> for handling characters: classification and
conversion. Every character classification facility has a name beginning with is and returns a
value of type int that is nonzero (true) if the argument is in the specified class and zero
(false) if not, <For example>, the isalnum function tests whether its argument is an
alphanumeric character - that is, one of the following in the C locale:
0 1 2 9, ABC
Y Z, ab c
y z.
This function is by definition equivalent to isalpha(c) ||isdigit(c) (the isalpha function
tests whether c is an alphabetic (upper- or lowercase) character. . In traditional C, these
functions take an argument of type char, but they return int».
Source: S.P.Harbison, G.L.Steele. C: A Reference Manual, 5th edition, Pearson Education,
2002, 534 p.
Transcribed Image Text:else printf("ERROR: Wrong input symbol - program" " terminates! \n"); exit(1); i++; void push(My_stack * s, char c) // push (insert) operation { // assume there is enough space for pushing next element! s -> top ++; s-> home[s -> top] = c; void pop(My_stack * s) // pop (remove) operation if(is_empty(s)) printf("ERROR: Nothing to pop - program terminates\n"); exit(1); } printf("%c", s -> home[s -> top -]); int is_empty(My_stack * s) // checking whether stack is empty or not return(s -> top < 0?1:0); Result of a sample run (CodeWarrior C/C++ 9.2, OS Windows XP) Process terminated. Press any key to c lose window. Enter the sequence (length is limited!>: EAS*Y *QUE***ST*** I0*N*** RESULT (after perforning pop operation>: SYEUQTSAONIE Note: Remember that «a stack is a list in which nodes can be added only at one end. Nodes can be accessed or removed only from that same end. When a new node is added it hides the previous end node, so in order to access that previous node the new node must first be removed. That is, the list works in a Last-In First-Out (LIFO) manner. The most recently added node is the first available for use, while the first node added is the last one available for use. By implementing the stack as an array you have a fixed limit on its size. And while you could obtain the array at runtime using malloc (), it still might be useful to have a more general solution. «There are tvwo kinds of facilities <in C> for handling characters: classification and conversion. Every character classification facility has a name beginning with is and returns a value of type int that is nonzero (true) if the argument is in the specified class and zero (false) if not, <For example>, the isalnum function tests whether its argument is an alphanumeric character - that is, one of the following in the C locale: 0 1 2 9, ABC Y Z, ab c y z. This function is by definition equivalent to isalpha(c) ||isdigit(c) (the isalpha function tests whether c is an alphabetic (upper- or lowercase) character. . In traditional C, these functions take an argument of type char, but they return int». Source: S.P.Harbison, G.L.Steele. C: A Reference Manual, 5th edition, Pearson Education, 2002, 534 p.
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY