Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Name: main.cpp (CS431 Assignment 2)
- * Author: Scott Giminiani
- * Date: Feb 17, 2011 2:44:04 PM
- * Location: /home/scott/development/workspace/CS431 Assignment 2/src/main.cpp
- * Description:
- */
- #include <iostream>
- using namespace std;
- int main(int argc, char* argv[]) {
- int n;
- cout << "Input 'number of elements': ";
- cin >> n;
- int a[n];
- for (int i = 1; i <= n; i++) {
- cout << "Input 'a(i)': ";
- cin >> a[i];
- }
- sort(n, a);
- for (int i = 1; i <= n; i++) {
- cout << a[i];
- }
- }
- void sort(int &n, int &a) {
- int j;
- //for ( j = 1; ???????????????? ;n - 1)
- if (a[j] > a[j + 1]) {
- move(a, j);
- }
- }
- void move(int &a, int &j) {
- int temp, k;
- temp = a[j + 1];
- a[j + 1] = a[j];
- findkay(k, j, a, temp);
- a[k] = temp;
- return;
- }
- void findkay(int &k, int &j, int &a, int &temp) {
- int sw;
- k = j;
- sw = 0;
- while (k > 1 && sw == 0) {
- if (a[k - 1] > temp) {
- a[k] = a[k - 1];
- k = k - 1;
- }
- else {
- sw = 1;
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement