CSH/KSH/PHP Numerical Bubble Sort Tutorial

CSH/KSH/PHP Numerical Bubble Sort Tutorial

CSH/KSH/PHP Numerical Bubble Sort Tutorial

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_sort.csh … 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_sort.ksh … the differences described by bubble_sort.csh

Link to some downloadable PHP programming code … rename to bubble_sort.php … which can supervise bubble_sort.ksh above using PHP exec command in the, aforementioned, “modes of use”:

  1. 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
  2. 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
  3. 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.

C++ Xcode Numerical Bubble Sort Tutorial

C++ Xcode Numerical Bubble Sort Tutorial

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 main.cpp for use.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Software, Tutorials and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

8 Responses to CSH/KSH/PHP Numerical Bubble Sort Tutorial

  1. Full-serie says:

    thanks for this information

  2. Thanks , I’ve recently been searching for info approximately this subject for ages and yours is the best I have came upon till now. But, what concerning the bottom line? Are you positive in regards to the supply?

  3. What i don’t realize is in fact how you’re now not actually a lot more well-liked than you may be right now. You are very intelligent. You know thus significantly in terms of this matter, made me in my view believe it from numerous various angles. Its like women and men aren’t involved until it‘¦s something to accomplish with Girl gaga! Your own stuffs excellent. Always handle it up!

  4. Solicitor says:

    Well I sincerely liked studying it. This tip offered by you is very effective for correct planning.

  5. Hello, you used to write magnificent, but the last few posts have been kinda boringΒ‘K I miss your tremendous writings. Past few posts are just a bit out of track! come on!

  6. hello!,I really like your writing so so much! share we keep in touch extra approximately your article on AOL? I need a specialist on this space to resolve my problem. May be that is you! Taking a look ahead to peer you.

  7. Martin Blais says:

    It’s actually a great and helpful piece of info. I’m glad that you simply shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>