반응형

#include <stdio.h>

#include <string.h>

#include <stdlib.h>


typedef struct stack* sptr;

typedef struct stack {

char data;

sptr low;

sptr high;

}stack;


sptr top;

int sCnt=0;


void push(char n)

{

sptr temp;

temp = (sptr)malloc(sizeof(stack));

if (sCnt == 0)

{

top->data = n;

top->low = NULL;

top->high = NULL;

sCnt++;

}

else if (sCnt >= 1)

{

temp->data = n;

temp->low = top;

temp->high = NULL;

top->high = temp;

top = temp;

sCnt++;

}

}

void pop()

{

sptr temp;

if (sCnt == 0)

{

printf("Nothing Inside! \n");

return;

}

else if (sCnt == 1)

{

sCnt = 0;

return;

}

else

{

temp = top;

top = top->low;

free(temp);

sCnt--;

}

}

void print()

{

int i;

sptr temp;


temp = top;

printf("sCnt: %d\n",sCnt);

for (i = 0; i < sCnt; i++)

{

printf("%c\n",temp->data);

if(i+1 < sCnt)

temp=temp->low;

}

}

반응형
블로그 이미지

개발자_무형

,