I am a newbie to programming . What i currently have is an array with 1000+ elements , i want to access only 10 of these elements at a time and perform some operations with these elements then input the next element in the array into the queue and so on. One method i could think of is pass all the elements of the array into the queue and pop 1 element of queue and append it into the new queue with max size 10.
But i doubt if its the right way to do it. Any leads as to how i must approach this problem? The code i have written until now creates a queue and takes in all the elements from the array. I am not sure of what i must do next.
import numpy as np
class Queue :
def __init__(self):
self.items=[]
def isEmpty(self) :
return self.items==[]
def enqueue(self, item):
self.items.insert(0,item)
def dequeue(self):
self.items.pop()
def size(self):
return len(self.items)
def printqueue(self):
for items in self.items:
print(items)
q= Queue()
a=np.linspace(0,1,1000)
for i in np.nditer(a):
q.enqueue(i)
I know this is silly for the experts but just wanted to know how i can approach this on my own. Edit : It was not a duplicate question of blkproc. as i come from C++ background using a queue was on my mind but using slice worked perfectly.