The source code is in C language and no external libraries are required. To compile the code, use the following command:
gcc .\odd_even_transposition_sort.c –pthread
To run the code:
./a.out (Ubuntu) or ./a.exe (Windows)
- The algorithm is implemented using threads, hence the –pthread tag is necessary to compile the code. The input sequence is sorted in ascending order. This is assumed.
- Array data structure is used for storing the elements and manipulating them.
- Appropriate swaps are done in process first at odd positions and then at even positions (indexing assuming 1 here, but array indices start with 0). Processes wait till the other processes complete in that round.
- An extra structure for storing the arguments to the comparison function in thread is implemented with required arguments like position, array and total number of elements.
Enter the number of elements in your sequence:
5
Enter your sequence:
9 2 4 6 8
By odd even transposition sort, the sorted sequence is:
2 4 6 8 9
The source code is in C language and no external libraries are required. To compile the code, use the following command:
gcc .\sasaki_time_optimal.c –pthread
To run the code:
./a.out (Ubuntu) or ./a.exe (Windows)
- The algorithm is implemented using threads, hence the –pthread tag is necessary to compile the code. The input sequence is sorted in ascending order. This is assumed.
- Linked List data structure is used for storing the elements and manipulating them. The node in the linked list represents a process and has the following properties: a. Two pointers to left and right elements (from Element structure which have the properties of value and isMarked) b. Two pointers to left and right nodes of the process c. One integer variable for storing area of the process node
- An extra structure for storing the arguments to the comparison function in thread is implemented with required arguments of a pointer to a process node. We do not use position or index information here. Hence, a linked list is used instead of an array.
- A process waits for the other processes to compelete in the same round. In each round, the processes exchange values with it's corresponding left and right nodes and update their areas.
Enter the number of elements in your sequence:
5
Enter your sequence:
9 2 4 6 8
By Sasaki's algorithm, the sorted sequence is:
2 4 6 8 9
The source code is in C language and no external libraries are required. To compile the code, use the following command:
gcc .\alternate_time_optimal.c –pthread
To run the code:
./a.out (Ubuntu) or ./a.exe (Windows)
- The algorithm is implemented using threads, hence the –pthread tag is necessary to compile the code. The input sequence is sorted in ascending order. This is assumed.
- Array data structure is used for storing the elements and manipulating them.
- An extra structure for storing the arguments to the comparison function in thread is implemented which includes the pointer to input array, total number of numbers, and the center of each triplet in a round.
- A process waits for the other processes to compelete in the same round. In each process, the triplets are updated with numbers sorted in ascending order.
Enter the number of elements in your sequence:
5
Enter your sequence:
9 2 4 6 8
By alternate time optimal sorting method, the sorted sequence is:
2 4 6 8 9