include <iostream>
using namespace std;
#define SIZE 10
template <class StackType> class stack {
StackType stck[SIZE];
int topOfStack;
public:
void init() {
topOfStack = 0;
}
void push(StackType ch);
StackType pop();
};
template <class StackType>
void stack<StackType>::push(StackType ob)
{
try {
if(topOfStack==SIZE) throw SIZE;
} catch(int) {
cout << "Stack is full.\n";
return;
}
stck[topOfStack] = ob;
topOfStack++;
}
template <class StackType>
StackType stack<StackType>::pop()
{
try {
if( topOfStack == 0)
throw 0;
} catch(int) {
cout << "Stack is empty.\n";
return 0;
}
topOfStack--;
return stck[topOfStack];
}
int main()
{
stack<char> stack1, stack2;
int i;
stack1.init();
stack2.init();
stack1.push('a');
stack2.push('x');
stack1.push('b');
stack2.push('y');
stack1.push('c');
stack2.push('z');
for(i = 0; i <3; i++)
cout << "Pop stack1: " << stack1.pop() << endl;
for(i = 0; i <4; i++)
cout << "Pop stack2: " << stack2.pop() << endl;
// demonstrate double stacks
stack<double> doubleValueStack1, doubleValueStack2; // create two stacks
// initialize the stacks
doubleValueStack1.init();
doubleValueStack2.init();
doubleValueStack1.push(1.1);
doubleValueStack2.push(2.2);
doubleValueStack1.push(3.3);
doubleValueStack2.push(4.4);
doubleValueStack1.push(5.5);
doubleValueStack2.push(6.6);
for(i = 0; i <3; i++)
cout << "Pop doubleValueStack1: " << doubleValueStack1.pop() << endl;
for(i = 0; i <4; i++)
cout << "Pop doubleValueStack2: " << doubleValueStack2.pop() << endl;
return 0;
}
yes
Wright a 'C' program for storage representation of 2-D array.
It seems that the number of allowed array dimensions is implementation specific and not set by the Java specifications. I'm sure that any Java implementation will allow a reasonable number of dimensions for any project you have. After a quick test, it seems that Java is not limited by an arbitrary number so much as a practical value. If you add hundreds of array dimensions, Java will allow you to do so as long as you have enough memory allocated for Java. After a bit of copy-pasting the program no longer ran, exiting with a StackOverflowError.
find even number in array
Yes, passing an array name to a pointer assigns the first memory location of the array to the pointer variable. An array name is the same as a pointer to the first location of the array, with the exception that an array name is a r-value, while a pointer is an l-value.
yes
Java has a very efficient built in implementation of quick sort. You can use it on any array of primitives or Comparable Objects by invoking Arrays.sort(<array>) See related link.
stack abstract datatype
An error or more commonly known as an Exception is a situation where the java program behaves in a way it is not supposed to do so. It is a problem in the code that is causing the JVM to terminate or throw error messages in the console. Ex: When you initialize an array list with 10 elements and try to access the 11th element in the array list you will get an array index out of bounds exception.
What is its size? How is its size determined and when (compile/run-time). What does the software using the array do when the array is empty? partially full? full? Avoid the software addressing elements of the array which are undefined, or addressing elements outside the bounds of the array When and who is responsible for allocating and freeing memory when the array is no longer needed (program or called procedure start/termination) or some other time determined during program execution. If the array is implementing a data structure such as a stack, queue, dequeue, list, etc. What is its implementation of the usual data structure operations, Create, Empty, List Items, Top, First, Last, Next, etc.
cod a program student degree array in c language
Wright a 'C' program for storage representation of 2-D array.
One efficient Java implementation for finding the median of two sorted arrays is to merge the arrays into one sorted array and then calculate the median based on the length of the combined array.
void bubblesort (int* array, int size) { if (!array size<2) return; int last_swap = size; while (last_swap>0) { int n=last_swap; for (int i=1; i<last_swap; ++i) { if (array[i]<array[i-1]) { array[i]^=array[i-1]^=array[i]^=array[i-1]; n=i; } last_swap = n; } }
It seems that the number of allowed array dimensions is implementation specific and not set by the Java specifications. I'm sure that any Java implementation will allow a reasonable number of dimensions for any project you have. After a quick test, it seems that Java is not limited by an arbitrary number so much as a practical value. If you add hundreds of array dimensions, Java will allow you to do so as long as you have enough memory allocated for Java. After a bit of copy-pasting the program no longer ran, exiting with a StackOverflowError.
A program which is used to count the number of numbers in an array using a 8085 microprocessor is known as a assembly language program.
find even number in array