Working with stack

In this example Stack data type is used to store 3-digit integers. There are three functions defined for the manipulation with the Stack data type:

void init_stack(Stack *stack);

int pop(Stack *stack, Element *elem);

int push(Stack *stack, Element elem);

Stack is implemented using singly linked list. List node and stack data type are defined as follows:

struct atom {
	int element;
	struct atom *next;
};
typedef struct atom Element;

typedef struct {
	Element *top;	
} Stack;

The main program creates a stack with 50 pseudorandom numbers from the range 100-999. Then it calls the function "armstrong" to create another stack that contains only Armstrong numbers from the previously created stack. By its argument "numArmstrong", the function "armstrong" returns the total number of found 3-digit Armstrong numbers on the stack.

Note that the number is called "Armstrong number" if the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 33 + 73 + 13 = 371.