c - Bubble sorting not working for large file, but it works for small file -


I'm having trouble with a large number of classified bubbles, this is an assignment, and my teacher clearly shows this big Asking to use bubble sort to sort the data. I tried to run in a small file and it works perfectly, but there is a problem to output anything to the big file. I do not know what the problem is. I have to use bubble sort also thanks. The small file "small.txt" is given below. The big file "big.txt" fits here, there are thousands of rows but there is a format similar to the small file, and my program is given below: I waited for 1 hour for output, and the program still Inside the progress to the big file.

small.txt

  FORD 2001 NISSAN 2000 JAYCO 2003   

program

  #include & Lt; Stdio.h & gt; #include & lt; String.h & gt; # Include & lt; Stdlib.h & gt; Int main () {FILE * read; Four line [110000]; Int i = 0, c, j, a; Make four * [111100]; Four * years [111100], * Swapier, * Swapmake; If ((read = fopen ("big.txt", "r")) == NULL {printf ("% s \ n", "big.txt can not open"); Exit (1); } C = 0; While (fgets (line, size (line), read!) = Null) {make [c] = strdup (strtok (line, "")); Year [c] = stdup (strotok (tap, "")); C ++; } (Foroi (year [a]) atoi (year [a + (a = 0; a & lt; a ++) 1])) {swapyear = year [a]; Swapmake = make [a]; Year [A] = Year [A + 1]; [A] = make [A + 1]; Year [A + 1] = Swapier; [A + 1] = swapmake; }}} For (j = 0; j & lt; = (c-1); j ++) {printf ("% s% s \ n", [j], year [j]); }}    

  This is the Bubble Sort Algorithm Note that it is close to each Expands all the way through data (contrary to the OP code)   

Step 1: Repeat steps 2 and 3 for i = 1 to enter two types of entries

Step 2: Set j = 1

Step 3: Repeat when j & lt; = N

  (A) if any [i] & lt; [J] then a [i] and a [j] [end of if] (b) set j = j1 [the end of the inner loop] [end of phase 1 outer loop]   < P> Step 4: Exit  

And there is a code implementation:

 for  (i = 0; i  arr [j + 1]) // Swapping status is checked {temp = arr [j] ; Arrival [j] = arrivals [j + 1]; Arrivals [j + 1] temporary =; }}}   

The above uses a temporary variable, usually a bad idea. Here is an example of using the XOR operator (and any floating variable)

  x = x ^ y (1) y = y ^ x (2) x = x ^ y (3)    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -