"코드는 struct에 int 데이터 유형이 있지만 struct의 char 데이터 유형에는 작동하지 않는 경우 작동합니다."C 대기열 구현의 데이터 유형
#include <stdio.h>
#include <stdlib.h>
#define null 0
struct node{
char data;//works fine if it is int data
struct node *next;
};
void push(struct node **head)//add element to the queue
{
struct node *newnode,*p,*q;
char d;
newnode=(struct node *)malloc(sizeof(struct node));
printf("\nenter the data you want to insert:");
scanf("%c",&d);
newnode->data=d;
if(*head!=null)
{
p=*head;
while(p!=null)
{
q=p;
p=p->next;
}
q->next=newnode;
newnode->next=p;
}
else
*head=newnode;
printf("the data is %c\n",newnode->data);
}
void pop(struct node **head)//pops element of the queue
{
struct node *p;
if(*head!=null)
{
p=*head;
*head=p->next;
printf("The data popped is %c \n",p->data);
free(p);
}
else
printf("no data to pop\n");
}
void traverse(struct node **head)//displays the queue
{
struct node *k;
if(*head!=null)
{
k=*head;
printf("\nthe data of the queue is:\n");
while(k!=0)
{
printf("%c\n",k->data);
k=k->next;
}
}
else
printf("no data\n");
}
void main()
{
struct node *head=null;
int i,n;
printf("how many data you want to enter\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
push(&head);
}
traverse(&head);
pop(&head);
traverse(&head);
}
출력 : 데이터가
이를 입력입니다 : 당신이 삽입 할
3
가 데이터를 입력
입력하려면 얼마나 많은 데이터 ./queue삽입하려는 데이터 : 데이터는
입니다. (210)가 삽입 할 데이터를 입력 데이터는 큐의
데이터입니다 : 팝
데이터는 큐의
데이터입니다
된다
"
디버거 무엇을 말하는가 ? – pm100
괜 찮 아 요 아무 문제 없어 .debugs 확인 – Paku
질문이 모호하다 .. 좀 더 구체적으로 할 수 있겠습니까? – Prabesh