U E D R , A S I H C RSS

스택/이태양

~cpp
#include<stdio.h>

int stack[5]={0,};
int index =0;
int top = 4;
int bottom = 0;

void push(int num)
{
	if(stack[top] != '\0')
	{
		printf("만땅.\n");
	}
	else
	{
		stack[index++] =num;
	}
}

void pop()
{
	if(stack[bottom] == '\0')
	{
		printf("더이상지울것이없습니다.\n");
	}
	else
	{
		stack[--index] = '\0';
	}
	
}

void print()
{
	
	for(int i=4;i>=0;i--)
	{
		printf("[%d]\n",stack[i]);
	}
}


void main()
{
	push(1);
	push(2);
	push(3);
	pop();
	pop();
	pop();
	pop();
	pop();
	push(4);
	push(5);
	push(6);


	
		
	print();
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:16
Processing time 0.0085 sec