#include <stdio.h>

int stack[100];
int top = -1;

void push(int x){
    stack[++top] = x;
}

void pop(){
   top--;
}

int main(){

    int arr[] = {1, 4, 2, 3};
    for(int i = 0; i < 4; i++){
    int k = arr[i];
        while(top > -1 && stack[top] < k){
            pop();
        }
        push(arr[i]);
    }
    for(int i = 0; i <= top; i++){
        printf("%d ", stack[i]);
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: