I am currently in the process of translating a block of Python code to C++ for speed purposes. This is the code as is (note, qsort is a quick sort I wrote myself):
base = sys.stdin.readline().split()
n = int(base[0])
m = int(base[1])
mult = m * 10
count = 1
output = []
while count != (n+1):
hold = output + []
if (n - count) + 1 >= mult:
rev = mult
else:
rev = n - count + 1
while rev != 0:
temp = sys.stdin.readline().split()
hold.append((int(temp[0])*count,temp[1], count))
count += 1
rev -= 1
hold = qSort(hold,len(hold))
output = hold[:m]
In essence, I am taking a few lines of input, adding them to a temporary list called hold, which holds new items and the existing output, and then my quicksort sorts the items according to their value (given as the first element/integer in the appended tuple). In Python this process is pretty simple, as I simply keep a list of tuples as hold and output, and each tuple contains three items: (1) integer used for sorting, (2) string, (3) integer. I was wondering what the best way to translate this to C++ was. Should I maintain 3 separate arrays and update all of them simultaneously, or should I use the list and tuples class. (Im trying to get my code to run as fast as it possibly can). Also, after deciding a method to use, how can I best translate the interplay between hold and output? How can I constantly effectively refresh hold at the beginning of the loop and effectively modify output at the end?
Any and all help is greatly appreciated! Cheers, mates!