For years and years, before the Internet, there were (and still are) the publicly accessible desktop application worlds of โฆ
- Windows with command line DOS
- Mac with command line (a lot like, but not exactly) Linux
โฆ and in either of these woooorrrllldddsss, or within any Unix or Linux environment, for years and years the C programming language was a big programming language presence.
Weโre hooking into this C programming today because up at our AlmaLinux web server we have the gcc (ie. GNU Compiler Collection) compiler available to compile C code into an executable program.
And we didnโt argue with the great Numerical Bubble Sort C code basis we visited at W3schools, thanks, and so weโre allowing users to โฆ
- tweak that code โฆ ie. weโd be mad not to control the bulk of what a user can do โฆ so that โฆ
- a user can add their own integer comma separated array list โฆ our PHP โฆ
- creates a new_bubble_sort.c โฆ and as the PHP explains โฆ
- use PHP exec and shell_exec to โฆ
$ gcc new_bubble_sort.c -o bubble_sort
$ ./bubble_sort - outputting a sorted array result
โฆ further to that discussion back with CSH/KSH/PHP Numerical Bubble Sort Tutorial, some time ago now, going along the same lines.
See โฆ
- PHP bubble_sort_c
php Numerical Bubble Sort โฆ overseeing โฆ
- C bubble_sort
c โฆ as a C code basis
Previous relevant CSH/KSH/PHP Numerical Bubble Sort Tutorial is shown below.
Here is a tutorial that follows up on yesterdayโs C++ Xcode Numerical Bubble Sort Tutorial as shown below, in an โoh, I forgotโ moment to make the link between the programming language C (and then C++) and its relationship to the Linux or unix shell scripting environment C Shell (weโll be saying CSH) (ie. today we go from a compiling language to an interpretive scripting set of languages), and CSHโs relationship with (the remarkable, the wonderful, the stupendous) awk, making functionality like numerical sorts quite easy just using shell scripting functionality. Well, thatโs how it started with work on the Linux command line here on this Mac laptop using the Terminal application. But, and am so very very very sorry to start a sentence with but โฆ but, well you see thereโs this โฆ but I digress โฆ I thought this could become a webpage or web application pretty easily by involving our old favourite PHP/exec combination (with code rewritten for Korn Shell (weโll be saying KSH)), because the rjmprogramming.com.au domain prefers KSH Korn shell โฆ so we proceeded along those lines โฆ and then lo and behold, it was apparent this could also be written for all the three PHP โmodes of useโ (latest โfoot in the doorโ tutorial for this would be PHP Modes of Use File Traverse Tutorial) weโve been talking about here lately at this blog โฆ namely PHP used with curl and the command line usage and the web browser usage.
Attempting to write code with a generic eye has the advantage that you end up with more flexibility, and, usually, more readable code.
So in the CSH scripting code youโll (need, maybe, to open up execute privileges via a command like chmod 755 ./bubble_sort.*sh and) see:
- The use of set via set variable=value syntax โฆ will fit in with all those lovers of interpretive languages (who like to add $ โฆ (who doesnโt?))
- The use of Command line arguments as with ./bubble_sort.csh 22 2 15 0 โฆ adds to the flexibility of your code with the user being able to tailor each usage of the script
- The CSH (and very C like) way of incrementing numerical variables via @ variable++ syntax
- The use of the underlying Linux operating system command to (numerically) sort (ie. sort -n[r]) โฆ whether it uses a โbubble sortโ am not totally sure โฆ but if not try the โbuble sortโ โฆ chortle, chortle
- The deliberate pointing out of any important restriction should there be one โฆ doh! โฆ in that we have a stipulation for a numerical data sort
Found this link very useful for C shell (ie. CSH) research โฆ thanks.
Link to some downloadable CSH programming code โฆ rename to bubble_sortcsh โฆ okay at Linux command line at this Mac, at least โฆ but for rjmprogramming.com.au web server usage needed โฆ
Link to some downloadable KSH programming code โฆ rename to bubble_sortksh โฆ the differences described by bubble_sortcsh
Link to some downloadable PHP programming code โฆ rename to bubble_sortphp โฆ which can supervise bubble_sort.ksh above using PHP exec command in the, aforementioned, โmodes of useโ:
- Via http transport layer (ie. web browsing, or โsurfing the netโ) in an Internet mode of use (eg: //www.rjmprogramming.com.au/Linux/awk/csh/bubble_sort.php?jsize=12&jmin=37&jmax=82&imode=0) in address bar of a web browser
- Via curl in an Internet mode of use (eg. curl //www.rjmprogramming.com.au/Linux/awk/csh/bubble_sort.php?jsize=12@37@82@0) at Linux or unix or Windows command line
- Via command line PHP in Linux or unix or Windows command line in a command or Intranet mode of use (eg. php ./bubble_sort.php 12 37 82 0) at a Linux or unix or Windows command line
Previous relevant C++ Xcode Numerical Bubble Sort Tutorial is shown below.
Here is a tutorial that uses the Xcode IDE on a Mac laptop to create a C++ desktop compiled application using a Bubble Sort method to numerically sort some numbers (ie. double).
Attempting to write code with a generic eye has the advantage that you end up with more flexibility, and, usually, more readable code.
Some ideas used in todayโs code include:
- The use of Preprocessor directives via #define identifier replacement syntax โฆ will fit in with all those lovers of interpretive languages
- The use of Command line arguments as with ./Test 22 2 15 0 โฆ adds to the flexibility of your code with the user being able to tailor each usage of the executable
- The use of a pointer to an array within a function, meaning that the data can be changed (ie. sorted) in situ rather than returning a value (or resorting to a global variable array) โฆ hence we use void numerically_sort_array(double* asort, int isize = ASIZE, bool ascending = (SMODE != 0)) โฆ you could change the void return, to return an error code, for example
- The C++ use of default values in parameters of the function call, making use of the Preprocessor directives, so that the call could make sense as numerically_sort_array(psarray); as numerically_sort_array(psarray, 1000, true); โฆ such thoughts come into play, in C++, also when considering Overloading
- The deliberate pointing out of any important restriction should there be one โฆ doh! โฆ in that we have a stipulation for a double data type array โฆ and have not implemented any Template functionality, on this occasion
Link to some downloadable C++ programming code โฆ rename to maincpp for use.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.