Yurttas/PL/OOL/Cplusplus/F/05/04/03/00/sort.cpp

From ZCubes Wiki
Revision as of 22:47, 6 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="cpp" line start="1" enclose="div">/* Copyright(C) 2002 All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. Perm...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 2002
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 2002.
11   author : Salih Yurttas.
12
13   sort.cpp
14*/
15
16
17#include "sort.h"
18
19using namespace std;
20
21template <class T>
22void sort(vector<T>& list) {
23  get_vector_item(list);
24
25  char sort_order_decision = get_char("A|D");
26
27  char sort_decision = get_char("B|I|Q|S");
28
29  switch((AD)(toupper(sort_order_decision))) {
30    case Ascending : {
31      switch((BIQS)(toupper(sort_decision))) {
32        case BubbleSort : bubblesort(list,
33                                     less<T>());
34                          break;
35        case InsertionSort : insertionsort(list,
36                                           less<T>());
37                             break;
38        case QuickSort : quicksort(list,
39                                   less<T>());
40                         break;
41        case SelectionSort : selectionsort(list,
42                                           less<T>());
43                             break;
44        default : cerr << "Error: sort_decision should be B|I|Q|S" << endl;
45                  exit(1);
46      }
47    }
48    break;
49
50    case Descending : {
51      switch((BIQS)(toupper(sort_decision))) {
52        case BubbleSort : bubblesort(list,
53                                     greater<T>());
54                          break;
55        case InsertionSort : insertionsort(list,
56                                           greater<T>());
57                             break;
58        case QuickSort : quicksort(list,
59                                   greater<T>());
60                         break;
61        case SelectionSort : selectionsort(list,
62                                           greater<T>());
63                             break;
64        default : cerr << "Error: sort_decision should be B|I|Q|S" << endl;
65                  exit(1);
66      }
67    }
68  }
69
70  put_vector_item(list);
71}