• 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
46 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
---------------------------------------------------------------

46 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. Thanks for sharing this nice post. Idioms can have a literal meaning in one situation and a different idiomatic meaning in another situation. German classes in Chennai | German language classes in Chennai | German Courses in Chennai

    ReplyDelete
  6. Now days, Learning French language is in very demand. People want to get job in France. French Classes in Chennai | French Training in Chennai

    ReplyDelete
  7. 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
  8. 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
  9. Hi dude.. This is very interesting for all kinda peoples


    Astronomy in Chennai

    ReplyDelete
  10. 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
  11. 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
  12. I really like your blog! Continue to write more! Very interesting!

    ReplyDelete
  13. you are posting a good information for people and keep maintain and give more update too.
    seo services india

    ReplyDelete
  14. 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
  15. 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
  16. Numpang Promo ya gan ^_^

    MeongQQ - Agen Poker Online Uang Asli Terpercaya Indonesia

    Hanya di MeongQQ.com Kamu Bisa Dapatkan Promo Bonus New Member 20%
    Ayo, cek web kami untuk info lebih lanjut dan info bonus lainnya.

    Hanya dengan Mengunakan 1 ID permainan saja, sudah bisa memainkan 6 game sekaligus..
    - Live Poker
    - Texas Hold'en Poker
    - Ceme
    - Ceme Keliling
    - Domino Qiu
    - Capsa Susun

    Piala Dunia 2018
    Poker Live Terpercaya
    Sejarah Poker Online
    Ceme Online

    yuk join ~~~

    ReplyDelete
  17. 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
  18. The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple and a good user-friendly interface.

    aws training in chennai

    ReplyDelete
  19. It is very useful information to learn a new language. It is very interesting blog to know the new information. Thank you for sharing this blog.
    German Classes in Chennai | German Language Classes in Chennai | German Courses in Chennai | German Language Course in Chennai

    ReplyDelete
  20. 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
  21. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.

    Node JS Training

    ReplyDelete
  22. 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
  23. 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
  24. 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
  25. Onekartu is a trusted online poker agent Site. Original Money Poker uses IDNPlay servers that are 100% proven trusted and fairplay. Deposit and Withdraw Process in Crotqq start from 10 thousand rupiah and with fast and safe process. Customer Service Crotqq is available 24 hours to help you if you are having problems. CrotQQ is always trying to become a trusted online poker agent for those of you who want a Fairplay Poker game.

    poker uang asli

    Dompetpoker.org is a card game that shares betting rules and is usually (but not always) in hand ranking. The Poker Online game is different in terms of how cards are shared. In the most modern Poker Games, the first round of betting starts with several forms. Type of card arrangement in Online Poker.

    poker online

    Specialist SEO.com is an Indonesian SEO Service launched in 2011 when search engines were in the early stages of developing their algorithms, Google was a big company that was very promising. Search engine optimization (SEO) has a completely different meaning. Since then many things have changed and internet marketing has become a necessity for every company that wants to survive in the online world competitively.

    Specialist SEO Indonesia SEO Services deal with Web Marketing technology from the start. After hours of research and development, trial and error, we can now offer the most reliable solutions in the world of Digital Marketing.

    Indonesian SEO Service

    You can chat, video call, phone, view photos, have fun, and even meet!
    online datingsite, online dating indonesia, free online dating, best online dating site free, online dating app, online dating terbaik, dating online chat, situs online dating, free dating sites without payment, dating online with video call, dating, meet me, meet, people nearby, soulmate, heart, online dating apps, free online dating, video call, audio chat, find your partner, setipe, skout, flurv, bigo live, Tinder, OkCupid, Hookup, BeeTalk
    online dating site

    Dompetpoker.org is a card game that shares betting rules and is usually (but not always) in hand ranking. The Poker Online game is different in terms of how cards are shared. In the most modern Poker Games, the first round of betting starts with several forms. Type of card arrangement in Online Poker.

    poker online

    ReplyDelete
  26. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi

    ReplyDelete

  27. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.


    AWS Training in Velachery | Best AWS Course in Velachery,Chennai

    Best AWS Training in Chennai | AWS Training Institutes |Chennai,Velachery

    Amazon Web Services Training in Anna Nagar, Chennai |Best AWS Training in Anna Nagar, Chennai

    Amazon Web Services Training in OMR , Chennai | Best AWS Training in OMR,Chennai

    ReplyDelete
  28. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    python course in pune
    python course in chennai
    python course in Bangalore

    ReplyDelete
  29. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    excel advanced excel training in bangalore | Devops Training in Chennai

    ReplyDelete
  30. 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