#include <stdio.h>

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

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

void pop(){
   top--;
}

int main(){

    int arr[] = {3, 5, 4, 2, 6};

    for(int i = 4; i >= 0; i--){

        int k = arr[i];

        while(top > -1 && arr[stack[top]] <= k){
            pop();
        }

        if(top == -1){
            printf("더 큰 숫자가 없음\n");
        }
        else{
            printf("%d\n", arr[stack[top]]);
        }

        push(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: