File: smat.sort.h

package info (click to toggle)
r-cran-pcapp 1.9-73-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 800 kB
  • sloc: cpp: 5,961; ansic: 917; sh: 13; makefile: 2
file content (72 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
    SMat - Simple Matrix Classes v0.1beta
    Copyright (C) 2011 by Heinrich Fritz (heinrich_fritz@hotmail.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SMAT_SORT_H
#define SMAT_SORT_H
#include "smat.base.h"

	void sort_R (const SCData<double> &a, SVecD &b) ;
	void sort (const SCData<double> &a, const SVecD &b) ;
	void sort_NC (const SCData<double> &a, const SVecD &b) ;

	void sort (const SVData<double> &a) ;
	void sort_order (const SVData<double> &a, const SVData<int> &b) ;
	void sort_order_NC (const SVData<double> &a, const SVData<int> &b) ;

	template <class T>
	T psort_V (const SVData <T> &a, t_size k)
	{
		T *pA = a ;

		double pivot, swapBuf ;

		t_size l = 0, lr = a.size () - 1, jnc, j ;

		while (l < lr)
		{
			pivot = pA[k] ;

			jnc = l ;
			j = lr ;

			while (jnc <= j)
			{
				while (pA[jnc] < pivot)
					++jnc ;

				while (pA[j] > pivot)
					--j ;

				if(jnc <= j)
				{
					sm_swap (pA [jnc], pA[j], swapBuf) ;
					++jnc ;
					--j ;
				}
			}

			if (j < k)
				l = jnc ;
			if (k < jnc)
				lr = j ;
		}

		return pA [k] ;
	}

#endif	//	#ifndef SMAT_SORT_H