• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Monday, January 3, 2011

Posted by venu k
28 comments | 11:53 AM
   
Quicksort is a good example of the divide and conquer strategy for
solving problems. In quicksort, we divide the array of items to be
sorted into two partitions and then call the quicksort procedure recu-
rsively to sort the two partitions, ie we divide the problem into two
smaller ones and conquer by solving the smaller ones

Quicksort recursive algorithm:

1 Select an element (called as pivot) x(p) of x .
2 Divide x into two batches x1 and x2 so that
all entries of x1 are < x(p) and
all entries of x2 are > x(p).
all entries of x3 are == x(p)
for each recursive call x3 will be placed to its sorted position.
To finish sorting we must sort x1 and x2.
3 Apply steps 1 and 2 again to each of x1
and x2, using further subdivision.
4 Repeat (recursively) until the sets to be
sorted have no more than one element.

#!/bin/bash
# SCRIPT : quicksort.sh
# USAGE : quicksort.sh
# PURPOSE: Sorts the list using quicksort algorithm.
# \\\\ ////
# \\ - - //
# @ @
# ---oOOo-( )-oOOo---
#
#####################################################################
# Define Functions Here #
#####################################################################

printnumbers()
{
echo ${ARRAY[*]}
}

sortnumbers()
{

local array=( `echo "$@"` )
local -a l
local -a g
local -a e
local x=

if [ ${#array[@]} -lt 2 ]; then
echo -n ${array[@]}
else
local pivot=${array[0]}

for x in ${array[@]}
do

if [ $x -lt $pivot ]
then
l=( ${l[@]} $x )
elif [ $x -gt $pivot ]
then
g=( ${g[@]} $x )
else
e=(${e[@]} $x)
fi

done

echo "`sortnumbers "${l[@]}"` ${e[@]} `sortnumbers "${g[@]}"`"

fi
}

#####################################################################
# Variable Declaration #
#####################################################################

clear

echo "Enter Numbers to be Sorted : "

read -a ARRAY

count=${#ARRAY[@]}

#####################################################################
# Main Script Starts Here #
#####################################################################

echo "--------------------------------------------------------------"

echo "Numbers Before Sort:"

printnumbers

echo "Numbers After Sort: "

sortnumbers "${ARRAY[@]}"

echo "--------------------------------------------------------------"


OUTPUT:

[venu@localhost shell]$ sh quicksort.sh
Enter Numbers to be Sorted :
12 54 32 90 76 54 -11 5 0 222 -46 32 -8 33 87 21 84 321 9
---------------------------------------------------------------
Numbers Before Sort:
12 54 32 90 76 54 -11 5 0 222 -46 32 -8 33 87 21 84 321 9
Numbers After Sort:
-46 -11 -8 0 5 9 12 21 32 32 33 54 54 76 84 87 90 222 321
---------------------------------------------------------------

28 comments:

  1. There's no need for command substitution in "local array=( `echo "$@"` )":

    local array=( "$@" )

    ReplyDelete
  2. local array=(`echo "$@"`) will not work.

    Instead use declare -a array=("${@}")

    ReplyDelete
  3. Qsort [string, dynamic pointer array]

    #include
    #include
    #include

    void sortstrarr(void *array, unsigned n);
    static int cmpr(const void *a, const void *b);

    int main (void) {
    char **strarray = NULL;
    int i = 0, strcount = 0;
    char line[1024];

    while((fgets(line, 1024, stdin)) != NULL) {
    if(strlen(line) == 1)
    continue;

    strarray = (char **)realloc(strarray, (strcount + 1) * sizeof(char *));
    strarray[strcount++] = strdup(line);
    }

    printf("### Before ###\n");
    for(i = 0; i < strcount; i++)
    printf("%2d: %s", i, strarray[i]);

    sortstrarr(strarray, strcount);

    printf("### After ###\n");
    for(i = 0; i < strcount; i++)
    printf("%2d: %s", i, strarray[i]);

    /* free mem... */
    for(i = 0; i < strcount; i++)
    free(strarray[i]);

    free(strarray);
    return 0;
    }

    static int cmpr(const void *a, const void *b) {
    return strcmp(*(char **)a, *(char **)b);
    }

    void sortstrarr(void *array, unsigned n) {
    qsort(array, n, sizeof(char *), cmpr);
    }

    ReplyDelete
  4. I read this article and its tell me how to maintain script function with easy way thanks for share it best resume template .

    ReplyDelete
  5. Pandith Raghavendra ji world No 1 Gold Medalist Astrologer - World Famous Astrologer in London, and he always give and more solution for astrology issue, if you have problem kindly look at:

    Indian Astrologer in UK | Top Astrology Services in London | Indian Astrologers in London UK

    ReplyDelete
  6. Thank you very much for sharing. It was very kind of you. company with the great experience in writing If you wonder what that is, it is an article I would want you to look through in case you are interested and eager to find out new things.

    ReplyDelete
  7. Hi dude.. This is very interesting for all kinda peoples


    Astronomy in Chennai

    ReplyDelete
  8. Thanks for appreciating. Really means and inspires a lot to hear from you guys.I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..Believe me, This is very helpful for me.
    Study in Germany Consultants in Chennai | Germany Education Consultants in Chennai

    ReplyDelete
  9. Thanks for appreciating. Really means and inspires a lot to hear from you guys.I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..Believe me, This is very helpful for me.

    Digital Marketing Company in Chennai

    Digital Marketing Company in India

    ReplyDelete
  10. I really like your blog! Continue to write more! Very interesting!

    ReplyDelete
  11. I was more than happy to find this web site. I need to thank you for your moment due to this unbelievable read!! I definitely savored every bit of it and I have you book-marked to see new things in your web site.
    Let's try to play five nights at freddy’s game now.

    ReplyDelete
  12. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Java Training In Bangalore

    ReplyDelete
  13. I regularly visit your site and find a lot of interesting information. Not only good posts but also great comments. Thank you and look forward to your page growing stronger.

    ReplyDelete
  14. Because of this, take note of that auto title crediting firms are in strict adherence to these laws and controls. 24/7 car title loans near me chicago

    ReplyDelete
  15. The training conferred by 10Daneces makes one build up his occupation openness. Unix Shell Scripting Training is granted in such a strategy, to the point that the understudies turn out to be in fact sound and that improves their capacity to work with this learning as technocrats.UNIX SHELL SCRIPTING is a script printed for the shell, or charge line indicator of any working plan. The shell is frequently taken as aneasy space particular program dialect. Trademark operations done by shell scripts incorporate record administration, program execution and printing content. 10Daneces gives direction by basically making the understudy work with UNIX SHELL SCRIPTING. The showing system is set in a manner that the learner gets a genuine vibe of the work. The information is prepared in a well ordered methodology so that the understudies can get that into their head and put into practice it when required. They are allowed to make and oversee tables, do scripting and real feel the beat. The mentors at 10Daneces is the most exceptional. They have the direct data of the technique and truly impart that to their understudies. The understudies feel certain that they are at 10Daneces for the instruction.

    10Daneces is the greatest Shell Scripting training institute in Noida with cutting edge foundation and lab offices and the choices of settling on various courses at Noida Location. 10Daneces in Noida gets ready a great many competitors for Shell Scripting at sensible charges that is redone remembering preparing and course content necessity of every participant.

    ReplyDelete
  16. The cash is given as a loan and is specifically saved into your own financial records, after which the loan reserves, in addition to a charge, are removed from your record toward the finish of the credit which more often than not is your next payday.Payday Loans Chicago

    ReplyDelete
  17. https://obirago.blogspot.com/2016/06/profil-member-shojo-complex16.html?showComment=1539157608893#c2681384654568182701

    Welcome to AsetQQ.com, the Best and Most Trusted Indonesian Online Poker Site. AsQQQ provides 6 games that can be played in 1 User Id only. Online Poker, DominoQQ, Bandar Ceme, Capsa Susun, Live Poker, Ceme Keliling Games, using Indonesian real money
    poker online

    Choosing an online casino agent is essential if people want to work on online gambling. http://www.dompetcasino.net/ to make the play scene should really be done so that the smoothness in playing gambling can be enjoyed gambling agency sites online casino agency page can also be done with a system of observing recommendations and recommendations from more experienced players.
    judi online

    happydomino is also the best and trusted Online Domino Poker site in Indonesia which has been proven by reputation and gained the trust of International Online gambling. Both the review of reputable poker sites and the quality of the games we provide do not need to be doubted. By providing the best service and providing assistance that is not complicated and we will provide an explanation that is as easy as possible so that you can easily understand it. We also provide playing tips and tricks so you can easily win in the best online gambling agent games in Indonesia. happydomino is guaranteed to be the fair play 100% online gambling site. There are no Robots in pure games Member vs Member. Our site is also equipped with the most sophisticated security system that is always updated on online gambling issues.

    poker online

    POKERSEJATI is a Poker site We provide interesting online game variants. You can access all of these games practically using just one account.

    situs poker

    JudiKartu is the jadwal bola, first trusted online betting agent in Indonesia that provides live baccarat, roulette and sicbo online services. Giving customer satisfaction and serving better than others.
    Always determined to be able to serve customers better. Trying to remain a Soccer Agent, Casino Agent, the best and most trusted Online Betting in Indonesia
    Jadwal bola

    Search engine optimization (SEO) or Indonesian SEO is the process of influencing the visibility of websites or web pages in search engine results - often referred to as "natural", "organic" or "earned" results. In general, the earlier (or rank higher on search results pages), and more often sites appear in the list of search results, the more visitors will receive from search engine users, and these visitors can be converted to customers.

    SEO can target various types of searches, including image search, local search, video search, academic search, news search and industry-specific vertical search engines.

    Indonesian SEO

    ReplyDelete
  18. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs online Training

    angularjs Training in marathahalli

    ReplyDelete