Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

shell program

Posted on 2000-04-24
12
Medium Priority
?
521 Views
Last Modified: 2010-04-21
send a shell program to implement buble sort
0
Comment
Question by:sriram_bandi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 2

Expert Comment

by:jonke
ID: 2746557
What's buble sort?
0
 
LVL 21

Expert Comment

by:tfewster
ID: 2746662
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
ID: 2748271
man sort
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

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

Author Comment

by:sriram_bandi
ID: 2750800
sorry it's actually bubble sort
0
 

Author Comment

by:sriram_bandi
ID: 2754316
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
 

Expert Comment

by:onalenna
ID: 2755824
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
ID: 2758740
Adjusted points from 50 to 125
0
 
LVL 1

Expert Comment

by:meerak
ID: 2761028
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
ID: 2761681
. or man csh
  man bash
  man tcsh
man perl (if you think of using perl as a shell ;-)
0
 

Accepted Solution

by:
misguided earned 250 total points
ID: 2768927
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
ID: 2772539
#!/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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

722 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