5.3. 박인서 ¶
//고통받기를 시작합니다.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node{
int val;
struct node* lnext;
struct node* rnext;
}node;struct node* lnext;
struct node* rnext;
void push(node *, int);
int pop(node *);
int find(node * ,int);
long cnt=1;
int pop(node *);
int find(node * ,int);
long cnt=1;
int main()
{
{
int a;
char ch5;
node head;
printf("초기값 설정 ㄱㄱ\n");
scanf("%d",&head.val);
head.lnext=NULL;
head.rnext=NULL;
for(;;)
{
return 0;
}char ch5;
node head;
printf("초기값 설정 ㄱㄱ\n");
scanf("%d",&head.val);
head.lnext=NULL;
head.rnext=NULL;
for(;;)
{
printf("push나 pop이나 exit 입력(push/pop/exit)\n");
scanf("%s",ch);
if(ch0=='e' && ch1=='x' && ch2=='i' && ch3=='t') break;
else if(ch0=='p' && ch1=='u' && ch2=='s' && ch3=='h')
{
else if(ch0=='p' && ch1=='o' && ch2=='p')
{
else
{
}scanf("%s",ch);
if(ch0=='e' && ch1=='x' && ch2=='i' && ch3=='t') break;
else if(ch0=='p' && ch1=='u' && ch2=='s' && ch3=='h')
{
printf("넣을 숫자 입력 ㄱㄱ(자연수만) : ");
scanf("%d",&a);
push(&head,a);
}scanf("%d",&a);
push(&head,a);
else if(ch0=='p' && ch1=='o' && ch2=='p')
{
a=pop(&head);
if(a==-1) printf("숫자 없음 ㅂㅅ아\n");
else printf("%d가 있었다 ㅂㅅ아\n",a);
}if(a==-1) printf("숫자 없음 ㅂㅅ아\n");
else printf("%d가 있었다 ㅂㅅ아\n",a);
else
{
printf("push나 pop이나 exit만 입력하라고...\n");
}return 0;
void push(node * target, int newval)
{
{
node * newnode=(node *)malloc(sizeof(node));
int a=1,c,i;
int * b;
cnt++;
for(c=1;;c++)
{
a=cnt;
b=(int *)malloc((sizeof(int))*c);
for(i=0;i
{
}
for(i=c-2;i>=1;i--)
{
}
newnode->val=newval;
newnode->lnext=NULL;
newnode->rnext=NULL;
if(b0==0) target->lnext=newnode;
else target->rnext=newnode;
free(b);
}int a=1,c,i;
int * b;
cnt++;
for(c=1;;c++)
{
if(a<=cnt && cnt<2*a) break;
a*=2;
}a*=2;
a=cnt;
b=(int *)malloc((sizeof(int))*c);
for(i=0;i
{
}
for(i=c-2;i>=1;i--)
{
}
newnode->val=newval;
newnode->lnext=NULL;
newnode->rnext=NULL;
if(b0==0) target->lnext=newnode;
else target->rnext=newnode;
free(b);
int pop(node * target)
{
{
int a=1,c,i;
int * b;
if(cnt==0) return -1;
if(cnt==1)
{
for(c=1;;c++)
{
a=cnt;
b=(int *)malloc((sizeof(int))*c);
for(i=0;i
{
}
for(i=c-2;i>=1;i--)
{
}
if(b0==0)
{
else
{
free(b);
cnt--;
return a;
}int * b;
if(cnt==0) return -1;
if(cnt==1)
{
cnt--;
return target->val;
}return target->val;
for(c=1;;c++)
{
if(a<=cnt && cnt<2*a) break;
a*=2;
}a*=2;
a=cnt;
b=(int *)malloc((sizeof(int))*c);
for(i=0;i
{
}
for(i=c-2;i>=1;i--)
{
}
if(b0==0)
{
a=target->lnext->val;
free(target->lnext);
target->lnext=NULL;
}free(target->lnext);
target->lnext=NULL;
else
{
a=target->rnext->val;
free(target->rnext);
target->rnext=NULL;
}free(target->rnext);
target->rnext=NULL;
free(b);
cnt--;
return a;