[ nesha_ @ 17.03.2011. 13:52 ] @
Potrebno je da sortiram jednostruko vezanu lancanu listu koristeci Bubble sort. E sad, kad cvorovima menjam polje sa vrednostima to nije problem, ali se ne snalazim kada treba da im zamenim pokazivace.. evo koda kako sam radio: Code: void SLList<T>::BubbleSort() { SLLNode<T> *tmp = new SLLNode<T>(); SLLNode<T> *tmp1 = new SLLNode<T>(); int i,j,hold; for(i=1 , tmp = head->next; i<=n-1 ; tmp = tmp->next , ++i) for( j=0 , tmp1 = head->next; j<n-i ; tmp1 = tmp1->next , ++j) if(tmp1->info < (tmp1->next)->info) { SLLNode<T>* pomoc = new SLLNode<T>(); SLLNode<T>* p2 = new SLLNode<T>(); pomoc = this->FindNodePtr(tmp1->info); p2 = tmp1; pomoc->next = tmp1->next; pomoc->next->next = p2; //hold = tmp1->info; //tmp1->info = (tmp1->next)->info; //(tmp1->next)->info = hold; } } template <class T> SLLNode<T>* SLList<T>::FindNodePtr(T el) { int m; m=0; SLLNode<T>* pred; for (SLLNode<T>* pred = head; pred!= tail; pred = pred->next) { m++; if(pred->next->info == el) { cout<<"pred: "<<pred->next->info<<endl; cout<<"br cvora: "<<m<<endl; return pred; }} |