Help Please!!! Need Help Programming Kanets ALgorithm

Here is the logical steps that I must program...so far I have programmed the sort in descending order I am having trouble figuring out how to split the original array into two new arrays for steps 2-5 can someone please help

step 1) sort the array of jobs

step 2) send first job to array B

step 3) send even numbered jobs to array B

step 4) send odd numbered jobs to array A

step 5) send the last job (if there is one) to array A

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include<iostream>
#include <cmath>
#include<algorithm>

using namespace std; 

//Prototypes
void Sort(int * , unsigned);
void split ( int *, unsigned );

//Initializing variables
int ar[100],n,i, firstOdd, countA, countB;
int A[100];	
int B[100];	

int main()	//Main Function
{
     
	 cout<<"How many jobs are there? ";	//Gets the size of the array
     cin>>n;
	 
     cout<<endl<<"Please enter the processing time for each job followed by the enter key."<<endl;	//Gets the contents of the array
     for(i=0;i<n;i++)
     {
		   cin>>ar[i];     	
     }
            
     Sort(ar, n);
     cout<<"The numbers listed in descending order are: ";
	 for(i=0;i<n;i++)
     {
		cout<< ar[i]<<" ";
     } 
     
     
     split ( ar, n);
     cout<<"The numbers listed in A are: ";
	 for(i=0;i<n;i++)
     {
		cout<< A[countA]<<" ";
     } 
     
	 split ( ar, n);
     cout<<"The numbers listed in B are: ";
	 for(i=0;i<n;i++)
     {
		cout<< B[countB]<<" ";
     } 
     	 	 
}
    	  	  
void Sort(int *array,  unsigned n)
{						//Sorts the array in desscending order
      bool swapped = true;
      int j = 0;
      int tmp;
      while (swapped) 
	  {
            swapped = false;
            j++;
            for (int i = 0; i < n - j; i++) 
			{
                  if (array[i] < array[i+1]) 
				  {
                        tmp = array[i];
                        array[i] = array[i + 1];
                        array[i + 1] = tmp;
                        swapped = true;
                  }
            }
      }
}

void split ( int * array, unsigned n)
{
	int countA, countB;
	countA = 0;
	countB = 0;
	int A[100];	
	int B[100];	
	
	for (int i = 0; i < n; i++)
	{
		if (ar[i] %2==1)
		{
			for (int i=0; i< n; i+1)
			{
					countA = i;
					A[countA];
			}
		}
           
		 else
		 {
			for (int i=0; i< 99; i++)
		    {
				 while ( ar[i]%2==0 )
				{ 
					countB = i;
					B[countB];
				}
			}
		 }
	}

}


Thanks for all your help in advance!
Last edited on
Topic archived. No new replies allowed.