struct set
{
int data;
struct set* link;
};
typedef struct set set;
set* alloc()
{
set *tmp;
tmp=(set*)malloc(sizeof(struct set));
return tmp;
}
int enq(set **head,int count,int data)
{
if(count>=8)
{
printf("que is full.\n");
return 0;
}
if(*head==0)
{
*head=alloc();
printf("input data : ");
scanf_s("%d",&data);
(*head)->>
(*head)->link=0;
count++;
return count;
}
else
{
count=enq(&(*head)->link,count,data);
return count;
}
}
int deq(set **head,int count,int data)
{
if(*head==0)
{
puts("que is empty\n");
return count;
}
else
{
*head=(*head)->link;
--count;
return count;
}
}
void list(set **head,int count,int data)
{
if(*head==0)
{
puts("que is empty.\n");
return;
}
else
{
set *tmp;
tmp=*head;
while(1)
{
printf("%d ",(*head)->data);
if((*head)->link==0)
{
printf("end of quue\n");
printf("count of arr is %d\n",count);
break;
}
else
{
*head=(*head)->link;
}
}
*head=tmp;
return;
}
}
void main()
{
int num,>
set *head=0;
while(1)
{
printf("1.Enque number\n2.Deque number\n3.show list\n > ");
scanf_s("%d",&num);
switch(num)
{
case 1:count=enq(&head,count,data); printf("input complete.\n"); system("pause"); break;
case 2:count=deq(&head,count,data); printf("delete complete.\n"); system("pause"); break;
case 3:list(&head,count,data); system("pause"); break;
}
system("cls");
}
return;
}
엔큐디큐 짜본건데 작동은 제대로 함. 근데 맞게 한건지 아닌건지 모르겠네 free도 안해주고 야매로 한 느낌이 너무 강해. 지적좀...
(카운트 있는건 문제에서 대기열을 8까지만 하라고 제한주길래 야매로 함..)
와 쉬발 여따가 올리니까 가독성 개병신이구나..
ㅇㅇ컬러스크립트나 스샷찍거니 하셈