{"id":10695,"date":"2014-11-21T05:02:20","date_gmt":"2014-11-20T18:02:20","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10695"},"modified":"2014-11-21T05:02:20","modified_gmt":"2014-11-20T18:02:20","slug":"cshkshphp-numerical-bubble-sort-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/cshkshphp-numerical-bubble-sort-tutorial\/","title":{"rendered":"CSH\/KSH\/PHP Numerical Bubble Sort Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php?jsize=25&#038;jmin=1&#038;jmax=295&#038;imode=0\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"CSH\/KSH\/PHP Numerical Bubble Sort Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/csh_sort.jpg\" title=\"CSH\/KSH\/PHP Numerical Bubble Sort Tutorial\"  id=\"qwqtoijximpept\" onmouseover=\" this.src=this.src.replace('.png','.JPG').replace('.jpg','.png').replace('.JPG','.jpg'); \"  \/><\/a><p class=\"wp-caption-text\">CSH\/KSH\/PHP Numerical Bubble Sort Tutorial<\/p><\/div>\n<p>Here is a tutorial that follows up on yesterday&#8217;s <a target=_blank href='#cxnbst' title='C++ Xcode Numerical Bubble Sort Tutorial'>C++ Xcode Numerical Bubble Sort Tutorial<\/a> as shown below, in an <i>&#8220;oh, I forgot&#8221;<\/i> 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&#8217;ll be saying <i>CSH<\/i>) (ie. today we go from a compiling language to an interpretive <i>scripting<\/i> set of languages), and CSH&#8217;s relationship with (the remarkable, the wonderful, the stupendous) <a target=_blank title='Linux awk ... programming language ... command' href='http:\/\/how-to.linuxcareer.com\/learning-linux-commands-awk'><i>awk<\/i><\/a>, making functionality like numerical sorts quite easy just using shell scripting functionality.   Well, that&#8217;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 &#8230; but, well you see there&#8217;s this &#8230; but I digress &#8230; 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&#8217;ll be saying <i>KSH<\/i>)), because the rjmprogramming.com.au domain prefers KSH Korn shell &#8230; so we proceeded along those lines &#8230; and then lo and behold, it was apparent this could also be written for all the three PHP <i>&#8220;modes of use&#8221;<\/i> (latest <i>&#8220;foot in the door&#8221;<\/i> tutorial for this would be <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10515' title='PHP Modes of Use File Traverse Tutorial'>PHP Modes of Use File Traverse Tutorial<\/a>) we&#8217;ve been talking about here lately at this blog &#8230; namely PHP used with <i>curl<\/i> and the <i>command line<\/i> usage and the <i>web browser<\/i> usage.<\/p>\n<p>Attempting to write code with a generic eye has the advantage that you end up with more flexibility, and, usually, more readable code.<\/p>\n<p>So in the <i>CSH<\/i> <i>scripting<\/i> code you&#8217;ll (need, maybe, to open up execute privileges via a command like <i><a target=_blank title='chmod information from computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/uchmod.htm'>chmod<\/a> 755 .\/bubble_sort.*sh<\/i> and) see:<\/p>\n<ul>\n<li>The use of <a target=_blank title='set' href='http:\/\/en.wikibooks.org\/wiki\/C_Shell_Scripting\/Variables'>set<\/a> via <i>set variable=value<\/i> syntax &#8230; will fit in with all those lovers of interpretive languages (who like to add <i>$<\/i> &#8230; (who doesn&#8217;t?))<\/li>\n<li>The use of <a target=_blank title='Command line arguments' href='http:\/\/en.wikibooks.org\/wiki\/C_Shell_Scripting\/Parameters'>Command line arguments<\/a> as with <i>.\/bubble_sort.csh 22 2 15 0<\/i> &#8230; adds to the flexibility of your code with the user being able to tailor each usage of the script<\/li>\n<li>The CSH (and very C like) way of incrementing <a target=_blank title='Incrementing values' href='http:\/\/www-cs.canisius.edu\/ONLINESTUFF\/UNIX\/shellprogramming.html#H'>numerical variables<\/a> via <i>@ variable++<\/i> syntax<\/li>\n<li>The use of the underlying Linux operating system command to (numerically) sort (ie. <a target=_blank title='Linux sort' href='http:\/\/lowfatlinux.com\/linux-sort.html'><i>sort -n[r]<\/i><\/a>) &#8230; whether it uses a <a target=_blank title='Bubble sort information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Bubble_sort'>&#8220;bubble sort&#8221;<\/a> am not totally sure &#8230; but if not try the <a target=_blank title='Buble ... sort ...' href='http:\/\/www.greatsong.net\/MUSIQUE-MICHAEL-BUBLE-IL-SORT-UN-ALBUM-DE-NOEL-28605.html'>&#8220;buble sort&#8221;<\/a> &#8230; chortle, chortle<\/li>\n<li>The deliberate pointing out of any important restriction should there be one &#8230; doh! &#8230; in that we have a stipulation for a numerical data sort<\/li>\n<\/ul>\n<p>Found this <a target=_blank title='C shell link ... thanks' href='https:\/\/bima.astro.umd.edu\/checker\/node22.html#369'>link<\/a> very useful for C shell (ie. CSH) research &#8230; thanks.<\/p>\n<p>Link to some downloadable CSH programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.csh_GETME' title='bubble_sort.csh'>bubble_sort.csh<\/a> &#8230; okay at Linux command line at this Mac, at least &#8230; but for rjmprogramming.com.au web server usage needed &#8230;<\/p>\n<p>Link to some downloadable KSH programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.ksh_GETME' title='bubble_sort.ksh'>bubble_sort.ksh<\/a> &#8230; the differences described by <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.csh-GETME' title='CSH vs KSH'>bubble_sort.csh<\/a><\/p>\n<p>Link to some downloadable PHP programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php_GETME' title='bubble_sort.php'>bubble_sort.php<\/a> &#8230; which can supervise <i>bubble_sort.ksh<\/i> above using PHP <a target=_blank title='PHP exec command' href='http:\/\/php.net\/manual\/en\/function.exec.php'><i>exec<\/i><\/a> command in the, aforementioned, <i>&#8220;modes of use&#8221;<\/i>:<\/p>\n<ol>\n<li>Via http transport layer (ie. web browsing, or &#8220;surfing the net&#8221;) in an <a target=_blank title='Internet information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Internet'>Internet<\/a> mode of use (eg: <a target=_blank title='Web browser usage' href='http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php?jsize=12&#038;jmin=37&#038;jmax=82&#038;imode=0'><i>http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php?jsize=12&#038;jmin=37&#038;jmax=82&#038;imode=0<\/i><\/a>) in address bar of a web browser<\/li>\n<li style='color:brown;'>Via <a target=_blank title='PHP information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/CURL'>curl<\/a> in an Internet mode of use (eg. <i>curl http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php?jsize=12@37@82@0<\/i>) at Linux or unix or Windows command line <\/li>\n<li style='color:blue;'>Via command line PHP in Linux or unix or Windows command line in a command or <a target=_blank title='Intranet information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Intranet'>Intranet<\/a> mode of use (eg. <i>php .\/bubble_sort.php 12 37 82 0<\/i>) at a Linux or unix or Windows command line <\/li>\n<\/ol>\n<hr \/>\n<p id='cxnbst'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10679' title='C++ Xcode Numerical Bubble Sort Tutorial'>C++ Xcode Numerical Bubble Sort Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/sort\/CPlusPlus_sort.png\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C++ Xcode Numerical Bubble Sort Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/sort\/CPlusPlus_sort.png\" title=\"C++ Xcode Numerical Bubble Sort Tutorial\"  id=\"qtoijximpept\" onmouseover=\" this.src=this.src.replace('.jpg','.JPEG').replace('.png','.jpg').replace('.gif','.png').replace('.jpeg','.gif').replace('.JPEG','.jpeg'); \"  \/><\/a><p class=\"wp-caption-text\">C++ Xcode Numerical Bubble Sort Tutorial<\/p><\/div>\n<p>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. <i>double<\/i>).<\/p>\n<p>Attempting to write code with a generic eye has the advantage that you end up with more flexibility, and, usually, more readable code.<\/p>\n<p>Some ideas used in today&#8217;s code include:<\/p>\n<ul>\n<li>The use of <a target=_blank title='Preprocessor directives' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/preprocessor\/'>Preprocessor directives<\/a> via <i>#define identifier replacement<\/i> syntax &#8230; will fit in with all those lovers of interpretive languages<\/li>\n<li>The use of <a target=_blank title='Command line arguments' href='http:\/\/www.cplusplus.com\/forum\/beginner\/5404\/'>Command line arguments<\/a> as with <i>.\/Test 22 2 15 0<\/i> &#8230; adds to the flexibility of your code with the user being able to tailor each usage of the executable<\/li>\n<li>The use of a <a target=_blank title='Pointer' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/pointers\/'>pointer<\/a> 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) &#8230; hence we use <i>void numerically_sort_array(double* asort, int isize = ASIZE, bool ascending = (SMODE != 0))<\/i> &#8230; you could change the <i>void<\/i> return, to return an error code, for example<\/li>\n<li>The C++ use of <a target=_blank title='Function default values' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/functions\/#defaultvalues'>default values in parameters<\/a> of the function call, making use of the Preprocessor directives, so that the call could make sense as <i>numerically_sort_array(psarray);<\/i> as <i>numerically_sort_array(psarray, 1000, true);<\/i> &#8230; such thoughts come into play, in C++, also when considering <a target=_blank title='Overloading and templates' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/functions2\/'>Overloading<\/a><\/li>\n<li>The deliberate pointing out of any important restriction should there be one &#8230; doh! &#8230; in that we have a stipulation for a <a target=_blank title='C++ basic data type' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/variables\/#fundamental'><i>double<\/i><\/a> data type array &#8230; and have not implemented any  <a target=_blank title='Overloading and templates' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/functions2\/'>Template<\/a> functionality, on this occasion<\/li>\n<\/ul>\n<p>Link to some downloadable C++ programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/sort\/main.cpp_GETME' title='Download me'>main.cpp<\/a> for use.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d10679' onclick='var dv=document.getElementById(\"d10679\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=C%2B%2B\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d10679' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d10695' onclick='var dv=document.getElementById(\"d10695\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Linux\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d10695' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Here is a tutorial that follows up on yesterday&#8217;s C++ Xcode Numerical Bubble Sort Tutorial as shown below, in an &#8220;oh, I forgot&#8221; moment to make the link between the programming language C (and then C++) and its relationship to &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/cshkshphp-numerical-bubble-sort-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,33,37],"tags":[122,175,176,234,280,284,405,623,677,707,932,997,1106,1166,1319,1339,1402,1406,1418],"class_list":["post-10695","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-software","category-tutorials","tag-awk","tag-c-shell","tag-c","tag-command-line","tag-csh","tag-curl","tag-exec","tag-interpretive","tag-korn-shell","tag-linux","tag-php","tag-programming","tag-scripting","tag-software-2","tag-tutorial","tag-unix","tag-web-application","tag-web-browsing","tag-webpage"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/10695"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=10695"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/10695\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=10695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=10695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=10695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}