Results 1 to 9 of 9

Thread: Working with Shell sort

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    13

    Working with Shell sort

    I'm doing a bank statement program and I'm having trouble loading the individual transactions against customer accounts and sorting them using shell sorting. Canb anyone help me with that?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,245

    Re: Working with Shell sort

    Here's a Shell Sort routine I posted in the VB6 forum a year or so back. I haven't converted it to .NET, but it is so simple that it shouldn't be very difficult.

    http://www.vbforums.com/showthread.p...ght=Shell+Sort
    My usual boring signature: Nothing

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,477

    Re: Working with Shell sort

    Why do you need to use shell sort? Is this homework? If you're getting your transactions into a DataTable then you wouldn't sort them there. The DefaultView property of the DataTable is a DataView and has sorting functionality built in. Collections and arrays also have built-in sorting functionality.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,245

    Re: Working with Shell sort

    Ya, and they probably use QSort, which will outperform Shell Sort in most cases, but Shell sort is a unique and interesting animal. Simple to implement, devilishly hard to explain.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    13

    Re: Working with Shell sort

    Quote Originally Posted by jmcilhinney
    Why do you need to use shell sort? Is this homework? If you're getting your transactions into a DataTable then you wouldn't sort them there. The DefaultView property of the DataTable is a DataView and has sorting functionality built in. Collections and arrays also have built-in sorting functionality.

    After getting my transactions into a data table, I have to sort them by account number and date and then send them to an array to print them.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,477

    Re: Working with Shell sort

    Once a DataTable is populated you cannot, without a lot of trouble, sort the DataRows it contains. The DataView class exists specifically to allow you to sort and filter data contained in a DataTable. It does not affect the data in the table in any way, but exposes a sorted and/or filtered view of that data, e.g.
    VB Code:
    1. 'Sort the data by account number in ascending order.
    2. myDataTable.DefaultView.Sort = "AccountNo ASC"
    3.  
    4. For Each row As DataRowView In myDataTable.DefaultView
    5.     MessageBox.Show(String.Format("AccountNo: {0}, TransactionID: {1}", row("AccountNo"), row("TransactionID")))
    6. Next row
    This will display the records in ascending order by account number regardless of what order they are actually in in the table. Note that the Sort property takes a String that basically represents an SQL GROUP BY clause. There is also a RowFilter property that takes an SQL WHERE clause to exclude various rows from the view. In many respects the DefaultView property is a filtered and sorted version of the Rows property. It contains DataRowView objects that are very similar to the DataRow objects contained in the Rows collection. Note that when you bind a DataTable to a control, like a DataGrid, it is actually the contents of the DefaultView that is displayed. When you click a column header in a bound DataGrid to sort by that column you are actually setting the Sort property of the DefaultView.

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    13

    Re: Working with Shell sort

    Quote Originally Posted by jmcilhinney
    Once a DataTable is populated you cannot, without a lot of trouble, sort the DataRows it contains. The DataView class exists specifically to allow you to sort and filter data contained in a DataTable. It does not affect the data in the table in any way, but exposes a sorted and/or filtered view of that data, e.g.
    VB Code:
    1. 'Sort the data by account number in ascending order.
    2. myDataTable.DefaultView.Sort = "AccountNo ASC"
    3.  
    4. For Each row As DataRowView In myDataTable.DefaultView
    5.     MessageBox.Show(String.Format("AccountNo: {0}, TransactionID: {1}", row("AccountNo"), row("TransactionID")))
    6. Next row
    This will display the records in ascending order by account number regardless of what order they are actually in in the table. Note that the Sort property takes a String that basically represents an SQL GROUP BY clause. There is also a RowFilter property that takes an SQL WHERE clause to exclude various rows from the view. In many respects the DefaultView property is a filtered and sorted version of the Rows property. It contains DataRowView objects that are very similar to the DataRow objects contained in the Rows collection. Note that when you bind a DataTable to a control, like a DataGrid, it is actually the contents of the DefaultView that is displayed. When you click a column header in a bound DataGrid to sort by that column you are actually setting the Sort property of the DefaultView.



    I'm going to try that method and see if it works. I don't know if I am explaining what I am supposed to do right. It is not really being populated I don't think. Loading the files would require when I run the program and hit the load button then a open dialog box will pop up and I will have to open both of the files. After opening then I would have to Process them which would be sorting the 2 files and storing them into an holding cell(array). In sorting I am looking for bogus/error checks and good checks. How about I send you a copy of the instructions and maybe you will be able to help me get started.

    Thanks for taking out time to help.

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,477

    Re: Working with Shell sort

    You mentioned data tables so I assumed that you were using a database. If you're loading this data from text files then I really hope it is an assignment because no commercial application should be doing that. If it's an assignment then you really do need to do the bulk of the work yourself. The first thing is to work out what aspects are under your control and what aren't. Have you been explicitly instructed to implement the shell sort algorithm for this?

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    13

    Re: Working with Shell sort

    Yes, I have to use the shell algorithm. It is an out of class example that will help us on the final project that we will have to do in 2 weeks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width