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...
I am taking a Data Structures and Program Design class. BUT, I am having trouble getting...
I am taking a Data Structures and Program Design class. BUT, I am having trouble getting access to the vectors so that I can compare the guesses with the random numbers. I’ve been working on this for several days and don't feel any closer to a solution and could really use some help as I really don't know how to get this to work. Thank you! The assignment is: Design an ADT for a one-person guessing game that chooses 4...
Hello, I have this question that I have been trying to solve for days. I am...
Hello, I have this question that I have been trying to solve for days. I am always able to solve the first part of the question, but I am never able to get the second part. Please help me understand how to set up this problem so I am able to solve it! Q: Let's revisit the banked curves from earlier to see another reason they are useful.We are building a road, and at one place we need to make...
I have a question about C++ programming Language class. I am confused with these terms and...
I have a question about C++ programming Language class. I am confused with these terms and what they are for. 1. Unix 2. Terminal 3. Git 4. CLOC 5. Linux Please explain each words and what's their jobs for C++. Also, if you know some good sources/websites, could you please provide me a link where I can learn how to use Unix, Terminal, Git, etc.
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...
Hi, I am taking MGMT460 and I have a question on an assignment for Work rules...
Hi, I am taking MGMT460 and I have a question on an assignment for Work rules ch.6 : What style of leadership is encouraged at Google (phrase your answer in one of the four styles described in Organizational Design, pages 160 – 166)? Explain (provide at least 3 examples from Work Rules, chapter 6).
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 There! I have a question to answer please, I don't understand it, it is about...
Hello There! I have a question to answer please, I don't understand it, it is about data communication and networking "Wireshark" Capture ICMP packets with “Wireshark” and analyze the results. Capturing Basics and Filters 1_ Create a filter to show only HTTP traffic with destination port 80. 2_ Create a filter to exclude ARP and ICMP traffic from visualization. 3_ Create a filter to show DNS queries to a specific domain. TIP: Use the keyword contains to search a specific...
Hello. I have a question related to astrology please: Because I am a little bit believe...
Hello. I have a question related to astrology please: Because I am a little bit believe in astrology and use different kind of app like Astrotalk or Yodha Pro that astrologers predicted based on birthday, time of birth, place of birth, city of birth and all of app people predicts with only the same results that made me believe. But my question is : if all of them just base on those information about my birth, time, place, does it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT