How Can Bubble Sort Optimize PCB Drill Bed Movements?

Click For Summary

Discussion Overview

The discussion revolves around the implementation of a bubble sort algorithm in C for a PCB manufacturing application. The goal is to optimize the movement of the drill bed by sorting a series of X coordinate points. Participants explore programming techniques, potential enhancements, and limitations of the proposed solution.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant outlines a specific task to create a C program that sorts X coordinates using bubble sort to minimize drill bed movements.
  • The provided code includes user input for X coordinates and options for sorting in ascending or descending order, but may contain errors and requires simplification.
  • Another participant suggests referring to a resource from Numerical Recipes for sorting algorithms and offers assistance with the bubble sort code.
  • A different participant proposes enhancements, such as reading data from a file for easier debugging and suggests using an array of structures to handle both X and Y values more effectively.

Areas of Agreement / Disagreement

Participants express varying opinions on the implementation details and possible improvements, indicating that there is no consensus on the best approach or the correctness of the current code.

Contextual Notes

Limitations mentioned include potential errors in the provided code, the need for user input which may complicate debugging, and the handling of both X and Y coordinates which is not addressed in the current implementation.

Who May Find This Useful

Individuals interested in programming, particularly in C, as well as those working on optimization problems in manufacturing processes may find this discussion relevant.

Apple4ever
Messages
8
Reaction score
0
Urgent help need ! Bubble sort !

hi all, I was asked to built a C programme using bubble sort. here is the Question.
TASK



A PCB manufacturing company requires a software program to convert a series of a table of drill data to minimise the movement of the drill bed to speed up production i.e.to place all the holes near each other row by row. This requires sorting out a series of X coordinates points in ascending/descending order.
You are required to write an ANSI C visual studio program to provide a numerical bubble sort, to a set of data. The user should be able to select from a menu system the type of bubble sort (ascending or descending), data input and final data display i.e. four options. The program should be user friendly and coded in best programming style: no global data, good use of functions and structured commenting. You are required to submit a word document report comprising of the final source code, sample test screen dumps and indications of limitations/enhancements of your program. Below is shown an example of basic pseudo code to help with the bubble sort approach to be used.
Pseudo code

Main
Define storage array input and output
Define menu
Option 1: Call array fill for input
Option 2: Call descending bubble sort on input for X data only
Option 3: Call ascending bubble sort on input for X data only
Option 4: Call display array output
Array fill
Input: Array size, Input arrays
Output: Array full of real numbers i.e. floats
Function: Single dimension loop using stdio to input data
Sort
Input: Array size, Input array, Output array, type of sort a or d
Output: Output array with sorted data
Function: Principle used bubble sort
Compare current value in array to array+1 element
Sort A: If value is greater than value+1 then swap over elements else carry on to next element
Sort D: If value is less than value+1 then swap over elements else carry on to next element
Repeat till you have compared all elements and no swaps have occurred and then return back the final output array

Can someone please check if the undermentioned answer is correct for the above question and can you simplify more if it is possible; any new answers are wellcome !

Work Done So far;

#include<stdio.h>
#define NUM 4
void array_direction(int ar[],char direction);
int main (void)
{
int n;
int x[NUM];
char order;
int y;

printf("This is the assignment 2 of Softwares for engineers \n");

printf("Welcome to the PCB Company :\n");
printf("Please enter the values of x coordinate to be sorted:\n");
for(n=0;n< NUM;n++)
{
printf(" please enter X Value %d:",n+1);
scanf("%3d",&x[n]);

}
printf(" How do you want your values of X coordinate sorted\n"); fflush(stdin);
printf("Pease enter A for ascending order or D for descending order\n:");
scanf("%c",&order);
array_direction(x, order);
printf(" The order is:\n");
for(y=0;y< NUM;y++)
{
printf("%3d, ",x[y]);
}
fflush(stdin);
getchar();
return 0;
}
void array_direction(int ar[],char direction)
{
int outer;
int inner;
int hold;
/*by using bubble Sort*/

/*For Ascending Order*/
if( direction == 'a' || direction == 'A')
{
for (outer = 0;outer < NUM; outer++)
{
for(inner = 0;inner < NUM;inner++)
{
if (ar[inner] > ar[inner+1])
{

//swap
hold = ar[inner];
ar[inner] = ar[inner+1];
ar[inner+1] = hold;
}
}
}
}







/* For Descending Order */
if(direction == 'd' || direction == 'D')
{
for (outer = 0;outer < NUM; outer++)
{
for(inner = 0;inner < NUM;inner++)
{
if(ar[inner] < ar[inner+1])
{
//swap
hold = ar[inner];
ar[inner] = ar[inner+1];
ar[inner+1] = hold;
}
}
}
}
}
 
Technology news on Phys.org


Hello,

Here is a link to one of the older C books from Numerical Recipes. Chapter 8 contains sorting algorithms. Check it out. If it is to complicated I can help you with some other code for a bubble sort.

http://www.nrbook.com/a/bookcpdf.php

Thanks
 


Thanks 4 da reply. i am new to this programming and i am not a Computer Student.

Can someone let me know the indications of limitations/enhancements of the above program...?

atleast 1 is enough thanks !
 


You might want to input the data from a file instead of user input. It will be easier to debug the program this way. Also, it's likely that the array will contain both x and y values. You could make an array of structures (since these can be assigned directly instead of having to use memcpy to move a pair of numbers).
 

Similar threads

Replies
20
Views
2K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 46 ·
2
Replies
46
Views
9K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K