Prerequisite:
Stacks and Queues using List | Data Structures | Python | Castor Classes
https://www.youtube.com/watch?v=bMVBW...
Python for beginners:
https://www.youtube.com/watch?v=egq7Z...

Code:

def reverseK(queue,k,n):

# code here

stacka=[];

queue2=queue[k:];

i=0;

while(i<k):

f=queue.pop(0);

stacka.append(f);

i=i+1;

queue=[];

i=0;

while(i<k):

f=stacka.pop(-1);

queue.append(f);

i=i+1;

queue=queue+queue2;

return queue

Telegram: https://t.me/clcoding_python

https://www.facebook.com/pirawenpython/

https://www.facebook.com/groups/pirawenpython/

Code:

def reverseK(queue,k,n):

# code here

stacka=[];

queue2=queue[k:];

i=0;

while(i<k):

f=queue.pop(0);

stacka.append(f);

i=i+1;

queue=[];

i=0;

while(i<k):

f=stacka.pop(-1);

queue.append(f);

i=i+1;

queue=queue+queue2;

return queue

Telegram: https://t.me/clcoding_python

https://www.facebook.com/pirawenpython/

https://www.facebook.com/groups/pirawenpython/

## 0 Comments:

## Post a comment