Question

In: Computer Science

Hello, I am currently taking software design and analysis class and have a question about those...

Hello, I am currently taking software design and analysis class and have a question about those 3 in cpp, can you please help me? thank you

- What is the complexity of pop()? push()? top()? size()? isEmpty()?

- Write a C++ implementation of push() in a linked-chain implementation of stack

- Write a C++ implementation of pop() in a linked-chain implementation of stack

Solutions

Expert Solution

- What is the complexity of pop()? push()? top()? size()? isEmpty()?
Answer: All these functions are of O(1) i.e constant time

========================

- Write a C++ implementation of push() in a linked-chain implementation of stack
- Write a C++ implementation of pop() in a linked-chain implementation of stack

struct node
{
   int val;
   node *next;
};

class stack{
   private:
       node *top;
   public:
       stack(){
           top = nullptr;
       }
      
       void push(int x){
           node *n = new node;
           n->val = x;
           n->next = top;
           top = n;
       }
      
       bool pop(int &x){
           if(top != nullptr){
               x = top->val;
               node *n = top;
               top = top->next;
               delete n;
               return true;
           }
           else
               return false;
       }
};


Related Solutions

Hello, this question relates to a class I am taking called introduction to C++. I have...
Hello, this question relates to a class I am taking called introduction to C++. I have no experience writing programs and outside of learning out of a textbook, and studying on my own, have little understanding of logic. I have been assigned a problem that requires me to write a program for a Grocery Bill, where the consumer inputs the price for 5 items, that the program calculates the total with a 6% sales tax. I really am not sure...
Hi, I am taking stats class and I have one question. I have been struggling with...
Hi, I am taking stats class and I have one question. I have been struggling with it for few hours. To investigate the fluid mechanics of swimming, twenty swimmers each swam a specified distance in a water-filled pool and in a pool where the water was thickened with food grade guar gum to create a syrup-like consistency. Velocity, in meters per second, was recorded and the results are given in a table below. The researchers concluded that swimming in guar...
Hello, I have been trying to answer this question for the last hour and I am...
Hello, I have been trying to answer this question for the last hour and I am still struggling could someone help me? The deadline is in 1hour! Perform an analysis of variance on the following data set. Do this by answering the questions below. Group 1 Group 2 Group 3 82 87 97 91 90 99 93 91 104 94 99 105 94 101 106 95 115 109 99 118 110 101 114 103 117 105 121 106 121 106...
Hello, I am studying and I am a bit confused about registers. There are segments registers,...
Hello, I am studying and I am a bit confused about registers. There are segments registers, data registers, pointer registers, index registers. But I do not really understand where these are found. Are they found in 8086 architecture? For instance if I ask what type of registers are found in 8086 architecture what will be the answer? All of these or only segment registers?
Hello! I am learning abaqus currently, but I do not know what the Analytic field is!...
Hello! I am learning abaqus currently, but I do not know what the Analytic field is! Can you tell me what is it? And how to use it with some examples! Thank in advance! I will thumb you up!
I am currently learning about internal influences in my marketing class. The statement was made that...
I am currently learning about internal influences in my marketing class. The statement was made that "Consumers are often very passionate about their attitudes and perceptions". The questions are: I) Think about brand loyalty and think of some attitudes that consumers hold and look beyond trying to assign rationality to attitudes. 2) What are some of the reasons a persons attitude towards a particular brand does not necessarily mean it is rational at all?
Hello! I have a question about the following problem, not sure how to approach it... This...
Hello! I have a question about the following problem, not sure how to approach it... This is from Mathematical Statistics and Data Analysis, Chapter 11, Problem 11.41 The Hodges-Lehmann shift estimate is defined to be d =median(Xi −Yj), where X1 , X2 , . . . , Xn are independent observations from a distribution F and Y1,Y2,...,Ym are independent observations from a distribution G and are independent of the Xi. Show that if F and G are normal distributions, then...
hello, I am having an issue with a question in my highway engineering course. the question...
hello, I am having an issue with a question in my highway engineering course. the question is: An equal tangent sag vertical curve has an initial grade of –2.5%. It is known that the final grade is positive and that the low point is at elevation 82 m and station 1 + 410.000. The PVT of the curve is at elevation 83.5 m and the design speed of the curve is 60 km/h. Determine the station and elevation of the...
Hello this is for C++ language. I am currently stuck on creating my api for Day...
Hello this is for C++ language. I am currently stuck on creating my api for Day Trading Stocks. as follows I need an api for *//Function Signature * * parameter: * * Return Value: ** *// Write the following function taking in an integer vector (vector &prices) consisting of all prices, in chronological order, for an hypothetical instrument. Your function recommends the maximum profit an investor can make by placing AT MOST one buy and one sell order in the...
Hello, i am currently working on an attendance system using MATLAB by the comparison of 2...
Hello, i am currently working on an attendance system using MATLAB by the comparison of 2 images of the same class, does anyone have any ideas or methods to use
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT