Solved

shell program

Posted on 2000-04-24
12
510 Views
Last Modified: 2010-04-21
send a shell program to implement buble sort
0
Comment
Question by:sriram_bandi
12 Comments
 
LVL 2

Expert Comment

by:jonke
Comment Utility
What's buble sort?
0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
This is a "homework" type question (that's been asked before!)  
See http://www.experts-exchange.com/info/usrcntr.htm for guidelines on acceptable questions
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
man sort
0
 
LVL 2

Expert Comment

by:jonke
Comment Utility
Oh- still don't see where the buble bit comes in though
0
 

Author Comment

by:sriram_bandi
Comment Utility
sorry it's actually bubble sort
0
 

Author Comment

by:sriram_bandi
Comment Utility
i am a kid in unix shell programing
i don't know how to develop array concept in shell that's why i am facing problems in implementing bubble sort.please experts, send that program(if and only if possible immediately)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:onalenna
Comment Utility
Have you ever programmed in C or C++? It's much easier moving from
those to shell programming. Good luck.
0
 

Author Comment

by:sriram_bandi
Comment Utility
Adjusted points from 50 to 125
0
 
LVL 1

Expert Comment

by:meerak
Comment Utility
You can use arrays in Shell scripts as in C programs.
eg.
You can use a[2]="test"
See "man page" for ksh for more details
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
. or man csh
  man bash
  man tcsh
man perl (if you think of using perl as a shell ;-)
0
 

Accepted Solution

by:
misguided earned 125 total points
Comment Utility
btw are u using sh? or bash?
   well there some basic loops u can use, for loops, while loop, until loop.

 syntax,

     for var in [list of strings]
        do
        done

     while [condition]
        do
        done

     until [condition]
        do
        done

then there the if syntax is if [condition]

 to use x++

u can x = `expr x + 1`;
then test it with if [x=0] like that easy?

from those structures i guess u could already make a bubble sort..:) happy coding.. for help on syntax write me at misguided@hotmail.com

                    misguided
     

           
0
 

Expert Comment

by:ravindra042100
Comment Utility
#!/usr/bin/ksh

print1()
{
echo "0: ${A[0]}"
echo "1: ${A[1]}"
echo "2: ${A[2]}"
echo "3: ${A[3]}"
}

SWAP=1
PASS=0
A[0]=2
A[1]=1
A[2]=5
A[3]=3
n=4
echo "Before:"
print1
while [ $SWAP -eq 1 ]
do
      SWAP=0
      times=$(($n-$PASS-1))
      i=0
      while [ $times -gt $i ]
      do
      
            j=$(($i+1))
            diff=$((${A[$j]}-${A[$i]}))
            if [ $diff -lt 0 ]
            then
                  TEMP=${A[$i]}
                  A[$i]=${A[$j]}
                  A[$j]=$TEMP
                  SWAP=1
              fi       
            PASS=$(($PASS+1))
            i=$(($i+1))
        done      
done
echo "After:"
print1
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now