Sorting a hash table based on value (not key)

Discussion in 'C Programming' started by vikas, Aug 16, 2007.

  1. vikas

    vikas Guest

    Hi,

    I want to sort a hash table based on value, not key. (key is of type
    string which hashes to some value and in each node i am maintaining
    frequency of that word(string) which is to be updated when that word
    is found. Now i want to print the words in decreasing order of
    frequency.
    vikas, Aug 16, 2007
    #1
    1. Advertising

  2. vikas

    Mark Bluemel Guest

    vikas wrote:
    > Hi,
    >
    > I want to sort a hash table based on value, not key.


    Good luck. Did you have a question?
    Mark Bluemel, Aug 16, 2007
    #2
    1. Advertising

  3. vikas

    Chris Dollin Guest

    vikas wrote:

    > I want to sort a hash table based on value, not key. (key is of type
    > string which hashes to some value and in each node i am maintaining
    > frequency of that word(string) which is to be updated when that word
    > is found. Now i want to print the words in decreasing order of
    > frequency.


    So what's not working?

    --
    Chris "crystal ball in use elsewhere" Dollin

    Hewlett-Packard Limited Cain Road, Bracknell, registered no:
    registered office: Berks RG12 1HN 690597 England
    Chris Dollin, Aug 16, 2007
    #3
  4. vikas

    CBFalconer Guest

    vikas wrote:
    >
    > I want to sort a hash table based on value, not key. (key is of
    > type string which hashes to some value and in each node i am
    > maintaining frequency of that word(string) which is to be
    > updated when that word is found. Now i want to print the words
    > in decreasing order of frequency.


    Take a look at the wdfreq.c demonstration application in
    hashlib.zip release. See:

    <http://cbfalconer.home.att.net/download/>

    The leading comment in that source is:

    /* Demonstration filter.
    This scans an input file for words, which consist of alpha-
    characters only, delimited by anything else. Each word is
    converted into lower case, and entered into a database with
    an occurance count. When all entry is complete the word
    list is formed and sorted, and the results dumped in order
    of number of occurances.

    The database is implemented through use of the hashlib
    package. When loaded, a singly linked list is formed from
    the content by the hashwalk feature, and sorted with a
    mergesort.

    by C.B. Falconer, 2002-03-12
    Put in public domain. Attribution appreciated.
    */

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Aug 16, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Me
    Replies:
    2
    Views:
    700
    Michael Beattie
    Jan 26, 2005
  2. rp
    Replies:
    1
    Views:
    499
    red floyd
    Nov 10, 2011
  3. Une bévue
    Replies:
    5
    Views:
    141
    Une bévue
    Aug 10, 2006
  4. Antonio Quinonez
    Replies:
    2
    Views:
    156
    Antonio Quinonez
    Aug 14, 2003
  5. Replies:
    9
    Views:
    127
    Martien verbruggen
    May 17, 2007
Loading...

Share This Page