Vous êtes sur la page 1sur 5

Past Paper 2010

Void enqueuer (Queue queue, int data){


If (end==Maxsize -1){
Printf(The queue is full);
Break;
}else
Queue[end] =data
end++;
}

While(not isempty(q))
Data= Dequeue(q)
Push(stk,data)
End while
While(not isempty(stk))
Data = Pop(stk)
Enqueue(q,data)
End while

#include <stdio.h>
Int main(){
Int target,num[20],I;
Printf(Please enter the target which you would like to search for)
Scanf(%d,&target);
For(i=0;i<20;i++){
If(num[i]==target){
Printf(The target %d is found at position %d,target,i);
Break;
}
}

If(x==20){
Printf(The target is not in the list);
}
}

CAPE 2011
#include <stdio.h>
Void main(){
Int arr[]={3,12,9,10,5,4};
Int temp,smallval,smallpos,x,y;
For (x=0;x<=4,x++){
Smallval= arr[x];
Smallpos=x;
}
For(y=x+1;y<=4;y++){
If( arr[y]<smallval){
Smallpos=y;}

Smallval=arr[y]
}
Temp=arr[x];
Arr[x]=smallVal;
Arr[SmallPos]=temp;
}
Return 0;
}

CAPE 2012
Int top=-1;

Int stk[100];

Void push(int elem){


If (top <99){
Top++;
Stack[top]=element;
} else
Printf(Stack overflow);
}
Int pop(){
Int element;
If (top==-1){
Printf(Stack underflow);
}else
Element=stk[top];
Top--;
Return element;
}

#include <stdio.h>
void main(){
Int marks[100],lower,upper,count=0,i;
Printf(Please enter the lower and upper boundaries);
Scanf(%d%d,&lower,&upper);
For (i=0;i<100;i++){
If(marks[i]>=lower && marks[i] <= upper)
Count = count +1;
}
If (count>0){
Printf(There are %d values in this range,count);

} else
Printf(There are no marks in the range);
}

CAPE 2013
Int stk[1000];
Int top=-1;

Void push(char data){


If(top <999){
Top=top+1;
Stk[top]=data;
} else
Printf(Stack Overflow);
}

char pop(){
char element = ;
If(top==-1){
Printf(Stack undeflow);
} else
Element=stk[top];
Top--;
Return element;
}

CAPE 2014
Count=0
While(not isempty(q))
Dequeue(q,element)

Count= Count+1
End While
Return count

Int num[100];

Int I;
For(i=0;i<100;i++){
Scanf(%d,val)
Num[i]=val;
}

Printf(Please enter key);


Scanf(%d,key);
For (i=0;i<100;i++){
If(num[i]==key)
Printf(the key is found at location %d);
}
If (i==100)
Printf(key not found);

Vous aimerez peut-être aussi