Open Prvdnx opened 1 year ago
Actually, there isn't a familiar sorting algorithm like bubble sort or quick sort here. When sorting a stack of 3 elements or 5 elements, I look at the maximum and minimum elements because my goal is to sort from minimum to maximum, and I do this following the instructions provided.
In larger datasets, such as with 100 or 500 elements, I first index the dataset by sorting it. Then, I perform an initial coarse sorting from the front, placing the larger elements towards the beginning as they tend to be more concentrated there. Afterward, I continue to sort them by placing them in a stack, taking into account both the maximum and minimum elements, and sequentially putting them in order from smallest to largest.
///////////////////////////// Project Summary ////////////////////////////
The instructions and objectives are as follows:
The game consists of two stacks named a and b. • Initially: Stack a contains a random number of distinct negative and/or positive numbers. Stack b is empty.
• The objective is to arrange the numbers in stack a in ascending order. • To achieve this, you can use the following operations:
The instructions;
sa: swap a - This operation puts the top 2 elements of stack a in reverse order. It does nothing if there is only one or zero elements in stack a. sb: swap b - This operation puts the top 2 elements of stack b in reverse order. It does nothing if there is only one or zero elements in stack b. ss: The ss operation combines sa and sb, executing them simultaneously. pa: push a - This operation places the top element of stack b onto the top of stack a. It does nothing if stack b is empty. pb: push b - This operation places the top element of stack a onto the top of stack b. It does nothing if stack a is empty. ra: rotate a - This operation shifts all elements in stack a up by 1 position. The first element becomes the last. rb: rotate b - This operation shifts all elements in stack b up by 1 position. The first element becomes the last. rr: The rr operation combines ra and rb, executing them simultaneously. rra: reverse rotate a - This operation shifts all elements in stack a down by 1 position. The last element becomes the first. rrb: reverse rotate b - This operation shifts all elements in stack b down by 1 position. The last element becomes the first. rrr: The rrr operation combines rra and rrb, executing them simultaneously.
Interesting! Thanks for your reply.
I forgot to mention, it seems as though memory was not properly freed. With reference to the individual nodes.
I forgot to mention, it seems as though memory was not properly freed. With reference to the individual nodes.
thanks I will check later
Hi there, Great Project!
What are the sorting algorithms used here?