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

  Threads in a multi-threaded process

What components of program state are shared across threads in a multi-threaded process? Can someone provide the answer with reference to operating system?

  Creating a c language code

Prepare a c code or Modify code to ask user to input five gpas. then the program computes the average of the gpa and prints it to screen.

  Issues with trusted platform modulewrite a research paper

issues with trusted platform modulewrite a research paper discussing the issues with trusted platform module tpm. your

  How to install and how to use it

How to install linux. How to use linux. How to install linux on virtual machine. Commands of linux. How to execute task in linux.

  Difference between eigrp and ospf

Imagine that you are a network engineer tasked with implementing either an EIGRP or OSPF solution for your routers.

  Create a simple file system explorer gui

For each of the four pieces of information identified above, you are to write a recursive method to calculate it. You are also to create JUnit test cases for the methods.) Two of the methods will need to return two values (a name/size or a name/..

  Discuss some of the roles that server operating systems

Discuss some of the roles that server operating systems can provide to a network, such as certificate services, Windows Deployment Services, and application pushing services.

  In working out your responses to the discussion question

in working out your responses to the discussion question you should choose examples from your own experience or find

  Discuss some possible algorithms for removing segments

Discuss some possible algorithms for removing segments in an unpaged, segmented memory. A program on the Core i7 references local segment 10 with offset 8000.

  Show the output of the screen when the program executes

Show the output of the screen when the program executes with a value of 200.

  Determine the utilization of the cpu

Two real time procedures are running on a computer. The 1st one runs every 25 msec for ten msec. The second one runs every 40 msec for fifteen msec.

  Example for processor scheduling

Give a (specific) example for processor scheduling in which preemption helps improve performance. Now discuss the feasibility of designing a preemptive disk scheduling algorithm for a disk read workload in which each job has the same priority. Do ..

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