3个回答
2013-08-26
展开全部
#include <stdio.h>
#include<stdlib.h>#define MAXLENGTH 10char Push(int &index,char c,char string[])
{
if(index<10)
{
string[index++]=c;
}
return c;
}char Pop(int &index,char string[])
{
char c ='\0'; if(index>=0)
{
c = string[index--];
string[index--]='\0';//设置成空,表示空的
}
return c;
}int main()
{
char string[MAXLENGTH];
int index=0; printf("入队列以后:\n");
Push(index,'a',string);
Push(index,'b',string);
Push(index,'c',string); for(int i=0;i<index;++i)
{
printf("%c ",string[i]);
} printf("出队列以后:\n");
Pop(index,string); //删除最后一个字符
for(int i=0;i<=index;++i)
{
printf("%c ",string[i]);
}
system("pause");
}
#include<stdlib.h>#define MAXLENGTH 10char Push(int &index,char c,char string[])
{
if(index<10)
{
string[index++]=c;
}
return c;
}char Pop(int &index,char string[])
{
char c ='\0'; if(index>=0)
{
c = string[index--];
string[index--]='\0';//设置成空,表示空的
}
return c;
}int main()
{
char string[MAXLENGTH];
int index=0; printf("入队列以后:\n");
Push(index,'a',string);
Push(index,'b',string);
Push(index,'c',string); for(int i=0;i<index;++i)
{
printf("%c ",string[i]);
} printf("出队列以后:\n");
Pop(index,string); //删除最后一个字符
for(int i=0;i<=index;++i)
{
printf("%c ",string[i]);
}
system("pause");
}
2013-08-26
展开全部
/*将顺序队列中的元素依次取出并打印*/
#include "stdio.h"
#include "conio.h"
#define NULL '\0'
#define MAXSIZE 50typedef struct
{ char data[MAXSIZE];
int front,rear;
}SEQUEUE;void initstack(SEQUEUE *q)/*初始化*/
{ q->front=-1;q->rear=-1; }void enqueue(SEQUEUE *q,char x) /*入队列*/
{ if(q->front==(q->rear+1)%MAXSIZE)
{ printf("queue is full !");
exit(0);
}
else
{ q->rear=(q->rear+1)%MAXSIZE;
q->data[q->rear]=x;
}
}int empty(SEQUEUE *q) /*判断空队*/
{ if(q->rear==q->front)
return 1;
else
return 0;
}char dequeue(SEQUEUE *q)
{ char v;
if(empty(q))
{ printf("queue is NULL !");
v=NULL;
}
else
{ q->front=(q->front+1)%MAXSIZE;
v=q->data[q->front];
}
return v;
}
main()
{ SEQUEUE a,*q;
char x,y;
q=&a;
initstack(q); while((x=getchar())!='$')
enqueue(q,x);
while(!empty(q))
{ y=dequeue(q);
printf("%3c",y);
}
getch();
}
#include "stdio.h"
#include "conio.h"
#define NULL '\0'
#define MAXSIZE 50typedef struct
{ char data[MAXSIZE];
int front,rear;
}SEQUEUE;void initstack(SEQUEUE *q)/*初始化*/
{ q->front=-1;q->rear=-1; }void enqueue(SEQUEUE *q,char x) /*入队列*/
{ if(q->front==(q->rear+1)%MAXSIZE)
{ printf("queue is full !");
exit(0);
}
else
{ q->rear=(q->rear+1)%MAXSIZE;
q->data[q->rear]=x;
}
}int empty(SEQUEUE *q) /*判断空队*/
{ if(q->rear==q->front)
return 1;
else
return 0;
}char dequeue(SEQUEUE *q)
{ char v;
if(empty(q))
{ printf("queue is NULL !");
v=NULL;
}
else
{ q->front=(q->front+1)%MAXSIZE;
v=q->data[q->front];
}
return v;
}
main()
{ SEQUEUE a,*q;
char x,y;
q=&a;
initstack(q); while((x=getchar())!='$')
enqueue(q,x);
while(!empty(q))
{ y=dequeue(q);
printf("%3c",y);
}
getch();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include
<stdio.h>
#include<stdlib.h>#define
MAXLENGTH
10char
Push(int
&index,char
c,char
string[])
{
if(index<10)
{
string[index++]=c;
}
return
c;
}char
Pop(int
&index,char
string[])
{
char
c
='\0'; if(index>=0)
{
c
=
string[index--];
string[index--]='\0';//设置成空,表示空的
}
return
c;
}int
main()
{
char
string[MAXLENGTH];
int
index=0; printf("入队列以后:\n");
Push(index,'a',string);
Push(index,'b',string);
Push(index,'c',string); for(int
i=0;i<index;++i)
{
printf("%c
",string[i]);
} printf("出队列以后:\n");
Pop(index,string);
//删除最后一个字符
for(int
i=0;i<=index;++i)
{
printf("%c
",string[i]);
}
system("pause");
}
<stdio.h>
#include<stdlib.h>#define
MAXLENGTH
10char
Push(int
&index,char
c,char
string[])
{
if(index<10)
{
string[index++]=c;
}
return
c;
}char
Pop(int
&index,char
string[])
{
char
c
='\0'; if(index>=0)
{
c
=
string[index--];
string[index--]='\0';//设置成空,表示空的
}
return
c;
}int
main()
{
char
string[MAXLENGTH];
int
index=0; printf("入队列以后:\n");
Push(index,'a',string);
Push(index,'b',string);
Push(index,'c',string); for(int
i=0;i<index;++i)
{
printf("%c
",string[i]);
} printf("出队列以后:\n");
Pop(index,string);
//删除最后一个字符
for(int
i=0;i<=index;++i)
{
printf("%c
",string[i]);
}
system("pause");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询