User:Jaspreetissaj/sandbox

== WAP TO IMPLEMENT ANAGRAM == struct stack {	char a[max]; int top; }; typedef struct stack; void anagram(stack *s,queue *q) {	char tmp,pvt; tmp=pop(s); enqueue(q,tmp);
 * 1) include
 * 2) include
 * 3) include
 * 4) define max 50

while((int)peek(s)>(int)peekqueue(q)) {		tmp=pop(s); enqueue(q,tmp); }	if(s->top>=0) {		pvt=pop(s); tmp=dqueue(q); if(q->rear>=0) while((int)tmp<(int)pvt) {			enqueue(q,tmp); tmp=dqueue(q); }		push(s,tmp); enqueue(q,pvt); tmp=dqueue(q); if(q->rear>=0) while((int)tmp>(int)pvt) {			enqueue(q,tmp); tmp=dqueue(q); }		push(s,tmp); while(!qempty(q)) {			tmp=dqueue(q); push(s,tmp); }	}	else while(!qempty(q)) {		tmp=dqueue(q); push(s,tmp); }	display(s); } void main {	char t;	stack s1; queue q1; int f=1,o=0; char a[23],str[23]; clrscr; create(&s1); create(&q1); printf("enter the string"); scanf("%s",a); int l=strlen(a); for(int i=l;i>0;i--) {		f=f*i; }

i=0; while(a[i]!='\0') {		push(&s1,a[i]); i++; }	while(o<=f-1) {		anagram(&s1,&q1); o++; }     printf("total combinations are= %d",o); getch; } void create(stack *s) {	s->top=-1; } void push(stack *s,char c) { if(s->top==max) {		printf("stack is full"); }	else {		s->top++; s->a[s->top]=c; } } char peek(stack *s) {	char c;	c=s->a[s->top]; return c; } char pop(stack *s) {	char c;	if(s->top==-1) {		return 0; }	else {		c=s->a[s->top]; s->top--; }	return c; } int sempty(stack *s) {	if(s->top==-1) return 1; else return 0; }

struct queue {	char b[max]; int front; int rear; }; typedef struct queue; void create(queue *s) {	s->front=0; s->rear=-1; } void enqueue(queue *s,char c) { if(s->rear==max) printf("queue is full"); else {		s->rear++; s->b[s->rear]=c; } } char peekqueue(queue *q) {	char c=q->b[q->rear]; return c; } char dqueue(queue *s) {	char c=s->b[s->front]; if(s->front==s->rear) {		s->front=0; s->rear=-1; }	else

s->front++; return c; } int qempty(queue *q) {	if(q->rear==-1) return 1; else return 0; } void display(stack *s) {	int i,j; if(s->top==-1) printf("stack empty"); else {		for(i=0;i<=s->top;i++) printf("%c",s->a[i]); printf("\n"); }

}