0

I am trying to implement linkedlist on python, which i have finished on c++. just for the function insertHead. i basically used the same algorithm.

c++

template <class T>
int L1List<T>::insertHead(T&& a){
    L1Item<T>   *p = new L1Item<T>(std::move(a));
    p->pNext = _pHead;
    _pHead = p;
    _size++;
    return 0;
}

python

def insertHead(self, _data):
    pNew = LLnode(_data)
    pNew.pNext = self.pHead
    self.pHead = pNew
    self.length += 1
    return True

i try to insert 10 million value of int. for c++ i get like 0.7s, while python run it for like 28s. why there is a huge difference??

0 Answers0