KrisLibrary  1.0.0
shift.h
Go to the documentation of this file.
1 #ifndef UTILS_SHIFT_H
2 #define UTILS_SHIFT_H
3 
4 #include <vector>
5 
13 
15 template <class T>
16 void ShiftForward(T& a, T& b, T& c)
17 {
18  T temp=c;
19  c=b;
20  b=a;
21  a=temp;
22 }
23 
25 template <class T>
26 void ShiftBackward(T& a, T& b, T& c)
27 {
28  T temp=a;
29  a=b;
30  b=c;
31  c=temp;
32 }
33 
35 template <class T>
36 void ShiftForward(std::vector<T>& v)
37 {
38  if(v.empty()) return;
39  T temp=v.back();
40  std::vector<int>::iterator i,prev;
41  for(i=--v.end();i!=v.begin();i--) {
42  prev=i; prev--;
43  *i = *prev;
44  }
45  v.front()=temp;
46 }
47 
49 template <class T>
50 void ShiftBackward(std::vector<T>& v)
51 {
52  if(v.empty()) return;
53  T temp=v.front();
54  std::vector<int>::iterator i,next;
55  for(i=v.begin();next!=--v.end();i++) {
56  next=i; next++;
57  *i = *next;
58  }
59  v.back()=temp;
60 }
61 
64 #endif
void ShiftForward(T &a, T &b, T &c)
Shift forward: set a&#39;=c,b&#39;=a,c&#39;=b.
Definition: shift.h:16
void ShiftBackward(T &a, T &b, T &c)
Shift backward: set a&#39;=b,b&#39;=c,c&#39;=a.
Definition: shift.h:26