Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sort() const {
- //bubble sort
- if (!empty() && !onlyOneNode()){
- int N = size();
- bool hasSwapped = false;
- for(int i=0; i<N; i++){
- int j = i;
- for (iterator it = ++begin(); it != end() && j < N; it++){
- // cout << *it << endl;
- // cout <<it._node->_prev->_data<<endl;
- if (*it < (it._node->_prev->_data)){
- hasSwapped = true;
- it._node->_next->_prev = it._node->_prev;
- it._node->_prev->_prev->_next = it._node;
- DListNode<T>* n_tmp = it._node->_next;
- it._node->_next = it._node->_prev;
- it._node->_prev->_next = n_tmp;
- DListNode<T>* p_tmp = it._node->_prev->_prev;
- it._node->_prev->_prev = it._node;
- it._node->_prev = p_tmp;
- it++;
- }
- j++;
- }
- // cout << "N: " << N << ", i: " << i << ", j: " << j << endl;
- if(!hasSwapped) break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement