write program to read a stack with size 10 then push 6 integer number - stack

write program to read a stack with size 10 then push 6 integer number and if number even put it in another stack and if odd put it in a third stack then print the 3 stack?
write program to read a stack with size 10 then push 6 integer number and if number even put it in another stack and if odd put it in a third stack then print the 3 stack?
//How do I solve it?

Related

How to subtract one stack from another in FIJI (ImageJ)?

Is there a way of how to subtract one stack of images from another stack using FIJI (ImageJ)?
To be more specific, I would like to find a quick way for such a subtraction, where first image of the first stack is subtracted from the first image of the second stack. Then second image of the first stack is subtracted from the second image of the second stack and so on.
You can use Process > Image Calculator... Specify the stacks and pick subtract in the following dialog to obtain the result. A pop up will ask if you'd like to process all images in the stack, click Yes.
If a rolling subtraction on a single stack is required (subtract i - 1 frame from frame i) use Analyze > Multi Kymograph > Stack Difference

Assuring stack pointer alignment using bitwise operators

Assume I want to reserve 8 bytes on the stack and I also want to make sure current stack pointer is 8 byte aligned. I have seen some codes that assure current sp is 8 bye aligned using this logic:
sp = sp & -8;
They AND it with the amount they are going to reserve on the stack (which of course is negative).
How does this logic work?
It works because negative numbers are represented in two's complement, so -8 is equivalent to ~7, of which the 3 least significant bits are 0s and the rest are 1s. ANDing this with a value clears the 3 least significant bits, which obviously results in it being 8-byte aligned. By the way, this trick only works to align things to powers of 2. If you had some strange reason to align things to a 12-byte boundary, for example, sp = sp & -12 would not work as intended.

Stack push and pop conceptual understanding

So, I'm working on a programming puzzle and need some help to see what I'm missing.
Here is the prompt:
What are the contents of the stack after running the following algorithm?
Given an array and an empty stack:
Push the values of the array onto the stack until a -1 value is found. Do not push the -1.
Pop the values in the stack until an even value is found or the stack is empty. The even value shouldn't be popped.
Repeat steps 1 and 2 until the stack is full or the array is read completely.
Type the contents of the stack from top to bottom, separated by a space, in the Answer box. If the stack is empty, enter a 0.
For this problem, use an array = {10,1, 3, 2, 3, -1, 4, 5, 7}, and a stack size of 6.
I honestly feel like this should be pretty easy but for some reason I'm missing something and continue to get it wrong.
Here is my thought process: (stack from bottom to top)
10 1 3 2 3
10 1 3 2
10 1 3 2 10 1
10 1 3 2 10
10 1 3 2 10 10
Final from top to bottom: 10 10 2 3 1 10
Is there something about stacks that I'm missing?
Any ideas?

Is it possible to add some stacks to one big stack?

I try to progamm a PET/CT-matching algorithm, and now I have a very difficult question to answer.
Is it possible to add some stacks to one big stack?
Ich have 55 Stacks with 55 Frames, where in each Stack two images with different alpha-values are combined.
Now I would like to create one big stack, when I slide from left to right the transparency of the image is changing and when I slide from the bottom to the top I want to see the different slices of the stack ......Is this possible or should I try another method?!
Thanks in Advance
Taepsi
ImageJ has support for multidimensional (up to 5 dimensions) stacks. On a higher level you can use Image->Hyperstacks->Stack to Hyperstack or Image->Stacks->Tools->Concatenate menu commands.
For use in a plugin, there is the function ImagePlus#setStack(ImageStack stack, int nChannels, int nSlices, int nFrames) and others. See documentation for ImagePlus class.
Here is a macro that demonstrates the use on a stack from ImageJ samples:
run("MRI Stack (528K)");
run("Duplicate...", "title=mri-stack-1.tif duplicate range=1-27");
run("Gaussian Blur...", "sigma=1 stack");
selectWindow("mri-stack.tif");
run("Duplicate...", "title=mri-stack-2.tif duplicate range=1-27");
run("Gaussian Blur...", "sigma=2 stack");
run("Concatenate...", " title=[Concatenated Stacks] open image1=mri-stack.tif image2=mri-stack-1.tif image3=mri-stack-2.tif image4=[-- None --]");

Stack direction and buffer overflow

In a downward growing stack, what's the rationale for stack variables to be written in an upward direction? For example, if I have char buf[200], say at memory address 0x400. When I write to this array, I will write from 0x400 to 0x600, which is toward previous stack frames. This makes the program vulnerable to buffer overflows that can take control over the program by overwriting return pointers, etc. So why not just write the array from 0x600 to 0x400?
It doesn't matter; when you try to write beyond 200 bytes, you are still trying to write to an address that does not belong to the array (out of bounds), hence buffer overflow.

Resources