Explain memory, time, build-in-function

Assignment Help Operating System
Reference no: EM13944820

I have two programs(Java and C++). They looks similar. But I need to explain why C++ is longer than java and what else to

explain such as memory, time, build-in-function and so on...
/ p1stack.cpp

#include <iostream>
#include <string>

using namespace std;


// stack exemptions
class EmptyStackException
{
};


// stack node
struct StackNode
{
string item;
StackNode* next;

StackNode(string s)
{
item = s;
next=0;
}

};


// stack class
class Stack
{

private:
StackNode* items; // stack items
int numItems; // number of items in stack

public:


//. initialize
Stack()
{
items=0;
numItems = 0;
}

// return number of items in stack
int size()
{
return numItems;
}


// push item onto stack
void push(string item)
{

StackNode* node = new StackNode(item);

if(items==0)

items = node;

else
{
numItems++;
node->next = items;
items = node;
}

}


// remove item from top of stack
string pop()
{

if(items == 0)
throw EmptyStackException();

else
{

string item = items->item;
items = items->next;
numItems--;
return item;

}
}


// return item from top of stack
string peek()
{

if(items == 0)
throw EmptyStackException();

else
{

string item = items->item;
return item;

}
}


// search for item in stack
bool search(string item)
{

StackNode* node = items;

while(node != 0)
{
if(node->item == item)
return true;
node = node->next;

}

return false;

}


// print out stack
friend ostream& operator <<(ostream& out, Stack& stk)
{

StackNode* node = stk.items;

while(node != 0)
{
out << node->item << " " << endl;

node = node->next;

}

return out;
}

};
// declare functions used by main
void print(Stack& stack);

int main()
{
Stack stack; // make stack


// push items onto stack
stack.push("Brazil");
stack.push("Canada");
stack.push("France");
stack.push("Mexico");
stack.push("Russia");
stack.push("Sweden");
stack.push("Brazil");
stack.push("Turkey");

print(stack);

cout << "stack.search(\"Brazil\") = "
<< stack.search("Brazil") << endl;

cout << "stack.pop() = " << stack.pop() << endl;

cout << "stack.pop() = " << stack.pop() << endl;

print(stack);

cout << "stack.search(\"Brazil\") = " << stack.search("Brazil") << endl;


return 0;
}

// print size and items in stack
void print(Stack& stack)
{
cout << stack << endl;

cout << "stack.size() = " << stack.size() << endl;

try
{
cout << "stack.peek() = " << stack.peek() << endl;

}

catch(EmptyStackException)
{
cout << ": The stack is empty." << endl;
}

import java.util.Stack;
public class P1_Stack
{ public static void main(String[] args)
{ Stack stack = new Stack();
stack.push("Brazil");
stack.push("Canada");
stack.push("France");
stack.push("Mexico");
stack.push("Russia");
stack.push("Sweden");
stack.push("Brazil");
stack.push("Turkey");
print(stack);
System.out.println("stack.search(\"Brazil\") = "
+ stack.search("Brazil"));
System.out.println("stack.pop() = " + stack.pop());
System.out.println("stack.pop() = " + stack.pop());
print(stack);
System.out.println("stack.search(\"Brazil\") = "
+ stack.search("Brazil"));
}
private static void print(Stack stack)
{ System.out.println(stack);
System.out.println("stack.size() = " + stack.size());
try
{ System.out.println("stack.peek() = " + stack.peek());
}
catch(java.util.EmptyStackException e)
{ System.out.println(e + ": The stack is empty.");
}
}
}
}

Reference no: EM13944820

Questions Cloud

Compute variable overhead spending and efficiency variances : Journalize the usage of direct materials and the assignment of direct labor, including the related variances. For manufacturing overhead, compute the variable overhead spending and efficiency variances and the fixed overhead spending and volume var..
How does locke define person : What does Ryle mean by a ‘category mistake' and how does he use this concept in making the case against dualism and other ‘mentalist' theories?
Write a paper on a nonprofit agency : Write a 2-3 page paper on a Nonprofit agency. Identify a nonprofit that you will use for several assignments
Along with discussing how the change : Along with discussing how the change itself will be perceived by the employees, talk about risks to the company, internal and external factors which will create barriers, and challenges to overcome them
Explain memory, time, build-in-function : I have two programs(Java and C++). They looks similar. But I need to explain why C++ is longer than java and what else to explain such as memory, time, build-in-function and so on...
Formula for producing a food and beverage item : Which of the following control tools links a restaurant's suppliers and receiving staff, ensuring that the proper quality of products is available for food production and service? A formula for producing a food and beverage item is called
Analytic-experimental marketing as political marketing : Assignement critically evaluate the potential and limitations of analytic and experimental marketing as a new political market recherche tool, drawing on examples from the 2012 US presidential election.
Think have helped make the camera : Considering what you have read and learned, what inventions do you think have helped make the camera what it is today?
Strengths and weaknesses of the key ideas of article : evaluate the two articles (use approx 300 words) i.e. discuss what you see as the strengths and weaknesses of the key ideas in each article

Reviews

Write a Review

Operating System Questions & Answers

  What do you think about running virus program on your phone

What do you think about running a virus program on your phone? Do you think it's necessary? Why do you think it's becoming necessary

  Design several security awareness posters

With the help of graphics program, design many security awareness posters on the following themes, updating antivirus signatures, watching out for e-mail viruses.

  What is the maximum size of the logical address

What is the page size in this system -  what is the maximum number of pages that can exist for a process and what is the maximum size of the logical address?

  Describe a client - server protocol

Identify and describe a client/server protocol used in everyday life and identify and describe three concerns dealing with Internet security and privacy?

  Automatic or traditional method to open a file

Some systems automatically open a document when it is referenced for the 1st time and close the file when the job terminates.

  The dining philosophers problem

Assume the Dining Philosophers problem. Explain the problems and assess what will happen if we allow the following code:a) Pick up chopstick on right, If chopstick on left is free, take it; else drop right chopstick. When done, drop both chopsticks.

  Determine the average seek time of traversed disk

Traversed Disk receives request to access random sector on random track. Suppose head starts at track 0. Determine the average seek time?

  Explain time which you have used quality-of-service in your

you were hired as a network engineer for a small firm that had just recently implemented a voice-over internet protocol

  How many reads from harddrive will the original query take

How many reads from the hard drive would the rewritten query take?

  A plug in and a helper application

Discuss similarities and differences between a plug-in and a helper application?

  How many primes are there that are less than 10,000

Write a program that prints out the first n primes, and n is input by the user.

  Find an arbitrary non-preemptive schedule of the tasks

Find an arbitrary non-preemptive schedule of the tasks. To make the problem simple, it is assume that the first instance of the three tasks {τ1, τ2, τ3} are invoked at time zero. Try to use integer linear programming framework to find the schedule..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd