1、入队,出队
#include"list.h"
#include"stdio.h"
queue *create_q()
{
queue *S=(queue*)malloc(sizeof(queue));
if(S==NULL)
{
printf("入参为空\n");
return;
}
S->front=0;
S->rear=0;
return;
}
//判空
int empty_queue(queue *S)
{
if(S==NULL)
{
printf("入参为空\n");
return NULL;
}
return S->front==S->rear?1:0;
}
//判满
int full_queue(queue *S)
{
if(S==NULL)
{
printf("入参为空\n");
return NULL;
}
return (S->rear+1)%MAX==S->front?1:0;
}
//入队
void push_queue(queue *S,datatype data)
{
if(S==NULL)
{
printf("入参为空\n");
return;
}
if(full_queue(S))
{
printf("该队已满\n");
return;
}
S->data[S->rear]=data;
S->rear=(S->rear+1)%MAX;
return;
}
//出队
void pop_queue(queue *S)
{
if(S==NULL)
{
printf("入参为空\n");
return;
}
if(empty_queue(S))
{
printf("该队为空\n");
return;
}
printf("出栈元素%d\n",S->data[S->front]);
S->front=(S->front+1)%MAX;
return;
}
//销毁队列
void free_queue(queue *S)
{
if(S==NULL)
{
printf("入参为空\n");
return;
}
if(empty_queue(S))
{
printf("该队列为空\n");
return;
}
S->front=0;
S->rear=0;
free(S);
}
2、思维导图
3
#include<stdio.h>
int sum(int n);
int main(int argc, char *argv[])
{
int ret=sum(0);
printf("%d\n",ret);
return 0;
}
int sum(int n)
{
if(n==10)
{
return 1;
}
else
{
return (sum(n+1)+1)*2;
}
}