C/C++队列应用(学习记录)

队列应用

已知一个数列组合是经过加密后的一串数字,那么现在知道这串加密后的数字,并且指导如何破解的方法,求加密前数字的组合是什么。
破解的方法:首先将第i个数删除,紧接着将第2个数放到
这串数的末尾,再将第3个数删除并将第4个数放到这串数的末尾,再将第5个数删除……直到剩下最后一个数,将最后一个数也删除。按照刚才删
除的顺序,把这些删除的数连在一起就是原始的数据。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 512
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void enqueue(char c);
char dequeue();
char array[SIZE];
int is_empty();
int is_full();
int tail=0;
int head=0; 
int main(int argc, char *argv[]) {
	char ch[521];
	int n ;
	printf("Enter encrypt content: "); 
	gets(ch); 
	int len = strlen(ch);
	printf("strlen : %d\n",len);
	for(n=0;n<len;n++)
	{
		enqueue(ch[n]);
	}
	printf("Enter Queue Finfish !\n");
	printf("Decrypt content ---> ");
	while(!is_empty())
	{
		//printf("arraychar #%s\n",array); 
		printf("%c",dequeue());
		if(!is_empty())
		{
			enqueue(dequeue());
		}
	}
	return 0;
}
void enqueue(char c)
{
	array[tail] = c ;
	tail = (tail+1)%SIZE;
}
char dequeue()
{
	char c;
	c = array[head];
	head++;
	return c;
}
int is_empty()
{
	return tail==head;
}
int is_full()
{
	return (tail+1)%SIZE==head;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值