bubble-sort

e-LMC extended Little Man Computer bubble embedded program continuous input

自作多情 提交于 2021-02-17 07:01:22
问题 I am looking for a e-LMC extended little man computer program that will accept an indefinite inputs and bubble-sort them. I need to have more inputs continuous and then do the bubble sort. INP //read 1st value STA 0 // for store INP // read 2nd value STA 1 // store INP // read 3rd value STA 2 // store LDA 1 // LOOP 1, STEP 1: SUB 0 // BRP STEP2 // if R0 and R1 are in order, don't swap them LDA 1 // Begin swapping registers STA 3 LDA 0 STA 1 // R1 = R0 LDA 3 STA 0 //R0 = temp STEP2 LDA 2 //

BubbleSort with recursion in Python3 - Returning “None”

社会主义新天地 提交于 2021-02-05 07:45:12
问题 I created a small function to do BubbleSort (just learning how to code) in Python 3 and I can't find the issue. Here is the code. It's returning "None" for some reason. Could someone please take a look? Thank you! arr = [1,5,2,7,3] def bubbleSort(array): count = 0 #print("array is currently",array) for idx in range(len(array)-1): if array[idx] > array[idx + 1]: array[idx],array[idx + 1] = array[idx + 1],array[idx] count += 1 #print("swaped and count is currently",count) #print("array is

How do I swap the nodes of a linked list in a bubble-sort algorithm?

故事扮演 提交于 2021-02-05 07:01:30
问题 In C I have to write a bubble sort function that swaps the nodes and not the values of a LinkedList, but I'm unable to accomplish it. Here is the code (As you can see the order is not correct): #include <stdio.h> #include <malloc.h> // malloc, free #include <stddef.h> // NULL // defining 'int' as data_t typedef int data_t; typedef struct node_s { data_t data; struct node_s* next; } node_t; node_t** list_new() { node_t** list = malloc(sizeof **list); if (!list) return NULL; *list = NULL;

How do I swap the nodes of a linked list in a bubble-sort algorithm?

Deadly 提交于 2021-02-05 07:00:32
问题 In C I have to write a bubble sort function that swaps the nodes and not the values of a LinkedList, but I'm unable to accomplish it. Here is the code (As you can see the order is not correct): #include <stdio.h> #include <malloc.h> // malloc, free #include <stddef.h> // NULL // defining 'int' as data_t typedef int data_t; typedef struct node_s { data_t data; struct node_s* next; } node_t; node_t** list_new() { node_t** list = malloc(sizeof **list); if (!list) return NULL; *list = NULL;

Sorting an array with bubble sort [duplicate]

我的梦境 提交于 2021-02-04 08:23:39
问题 This question already has answers here : How can I sort arrays and data in PHP? (12 answers) Closed last year . I am trying to create an algorithm that shows each step of bubble sort, sorting one number at a time. I was was able to sort the number at the first index, but I need to figure out how to sort all the numbers. $x = array (9,7,5,3,0); $count = count($x); for($i = 0; $i < $count-1; $i++ ) { $temp = $x[$i+1]; $x[$i+1] = $x[$i]; $x[$i] = $temp; echo '<pre>'; print_r($x); } My current

Python - What is the space complexity when tuple swap is used in bubble sorting?

此生再无相见时 提交于 2021-01-28 10:09:39
问题 Consider the following bubble sort program: arr = map(int, raw_input().split(' ')) print "Unsorted: \n{arr_name}".format(arr_name = arr) for j in range(len(arr) - 1, 0, -1): for i in range(j): if (arr[i] > arr[i + 1]): arr[i], arr[i + 1] = arr[i +1], arr[i] print "Sorted: \n{arr_name}".format(arr_name = arr) Usually a temp variable is used for sorting and that would be mean a space complexity of 0(1) . But my understanding is that, tuple swap is only a reassignment of identifiers to objects

how to write a C code that “bubblesorts” the strings in a 2D array?

假如想象 提交于 2021-01-07 02:35:28
问题 #include <stdio.h> int main() { int N, i, j, k, z, v, x, c; printf("Determine the number of your words: \n"); scanf("%d", &N); char dict[50][50]; char tmp[50]; for(i=0; i<N; i++) { printf("Determine your %d. word: \n", i+1); scanf("%49s", &dict[i]); } for(j=0; N-1; j++) { for(k=0; N-i; j++) { if(dict[k][0]>dict[k+1][0]) { for(z=0; z<50; z++) { tmp[z]=dict[k][z]; } for(v=0; v<50; v++) { dict[k][v] = dict[k+1][v]; } for(x=0; x<50; x++) { dict[k][x]=tmp[x]; } } } } for(c=0; c<N; c++) { printf("

How to BubbleSort an array in descending order?

点点圈 提交于 2020-12-14 23:36:13
问题 private static double[] BubbleSortAscending(double[] numberArray) { int arrayLength = numberArray.Length; for(int i = 0; i < arrayLength - 1; i++) { for(int j = 0; j < arrayLength - 1 - i; j++) { if(numberArray[j] > numberArray[j + 1]) { double num = numberArray[j]; numberArray[j] = numberArray[j + 1]; numberArray[j + 1] = num; } } } return numberArray; } Hello, in the code above I have managed to make it so that it sorts an array in ascending order, however I am fully stuck and stumped on

How to BubbleSort an array in descending order?

天大地大妈咪最大 提交于 2020-12-14 23:34:11
问题 private static double[] BubbleSortAscending(double[] numberArray) { int arrayLength = numberArray.Length; for(int i = 0; i < arrayLength - 1; i++) { for(int j = 0; j < arrayLength - 1 - i; j++) { if(numberArray[j] > numberArray[j + 1]) { double num = numberArray[j]; numberArray[j] = numberArray[j + 1]; numberArray[j + 1] = num; } } } return numberArray; } Hello, in the code above I have managed to make it so that it sorts an array in ascending order, however I am fully stuck and stumped on