Skip to main content

Posts

Showing posts from January, 2007

C++ implementation of quick sort using std::list

An C++ implementation of quick sort using std::list. The code is as follow: #include using namespace std; typedef list ::iterator ITER; void quicksort(list * seq, ITER middle, ITER end){ ITER iter = end; ITER begin = middle; if(middle == end) { return; } else{ --iter; } ITER temp; while(iter != middle){ if(*iter < *middle){ temp = iter; --iter; begin = seq->insert(begin,*temp); seq->erase(temp); } else{ --iter; } } quicksort(seq,begin,middle); quicksort(seq,++middle,end); }

Pseudocode of Teiresias algorithm

//the candidate stack Stack S; //check if P is prefix less than Q //P=AC..T and Q=T.G, P is prefix less than Q. //P=AC..TA and Q=AC..T, P is prefix less than Q. bool PrefixLess(P,Q); //check if P is suffix less than Q //P=AC..T and Q=AC.GT, Q is suffix less than P. //P=C.GT and Q=AC.GT, Q is suffix less than P. bool SuffixLess(P,Q); //check if P and Q are convolutable bool isConvolutable(P,Q); //convolute P and Q Sequence Convolute(P,Q); //check from the result list, judge if P is maximal bool isMaximal(P); //add P to result list bool AddToResultList(P); Teiresias(){ P=S.top(); for Q=S.Location(P).next() to S.bottom(){ if isConvolutable(P,Q){ R=Convolute(P,Q); S.push(R); Teiresias(); } } for Q=S.Location(P).next() to S.bottom(){ if isConvolutable(Q,P){ R=Convolute(Q,P); S.push(R); Teiresias(); } } if isMaximal(P){ AddToResultList(P); } }