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

  Implementation of algorithms for process management

The Shortest Job Next (SJN) algorithm queues processes in a way that the ones that use the shortest CPU cycle will be selected for running rst.

  Develop a user mode command interpreter

Develop a user mode command interpreter which support list-short.

  Memory allocation in operating system

Analysis and implementation of algorithms for memory allocation in operating system, Explain First- t and best- t methods are used in memory allocation in operating systems.

  Stand alone child process

Forking the child process

  Write a multi-threaded program

Write a multi-threaded program to solve producer and consumer problem

  Marginal and average cost curves

n a competitive market place (pure competition) is it possible to continually sell your product at a price above the average cost of production.

  Simulating operating systems scheduling

Simulate the long-term scheduler, the short-term scheduler and the I/O scheduler of the computer using the First-Come-First-Serve algorithm.

  Issues with trusted platform module

Research paper discussing the issues with Trusted Platform Module (TPM)

  Threads

Explain a complication that concurrent processing adds to an operating system.

  Design and programming

Use the semaphore methods to control the concurrency of the solution

  Virtual machines

Virtual machines supported by a host operating system

  Discuss an application that benefits barrier synchronization

Discuss an application that would benefit from the use of barrier synchronization

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