Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. want to know the index of ArrayList during BinarySearch

want to know the index of ArrayList during BinarySearch

Scheduled Pinned Locked Moved C#
databasehelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rizwan Rathore
    wrote on last edited by
    #1

    Hi all, I am trying to develop a text mining engine and in it i need to work on large number of files...and deal with lots of words... i ve made a word class which has following variables

    public string term;
    public int df;
    public ArrayList tf = new ArrayList();
    public ArrayList docID= new ArrayList();
    public static int count;

    here term is the variable wich contains the actual value of the word. now when user queries for a word i need to search all these terms and find out whether the term user wants exists or not.... i ve this word class sorted w.r.t the "term" variable so it means that i can apply binary search for finding the user query.....i m doing this by adding all the term variables of the class in an arraylist and then applying binary search over it....but the problem is that i need to know the index of the arraylist where the user's queried term exists.....and i dont know the way to find out the index :( i ve added the sample chunk of code here.....anyone plzz help

    //adding all the term variables of Terminology class to the allTerms ArrayList.......
    for(int i = 0; i < Terminology .count; i ++ )
    {
    allTerms.Add(word[i].term);
    }

    //queryList is the ArrayList that contains the pharase queried by the user in the form of //one string at one index
    for(int j = 0; j < queryList.Count; j ++)
    {
    if(allTerms.BinarySearch(queryList[j]) >= 0)
    {
    need to know the index of allTerms ArrayList.
    }
    }

    looking forward for help Regards,

    L 1 Reply Last reply
    0
    • R Rizwan Rathore

      Hi all, I am trying to develop a text mining engine and in it i need to work on large number of files...and deal with lots of words... i ve made a word class which has following variables

      public string term;
      public int df;
      public ArrayList tf = new ArrayList();
      public ArrayList docID= new ArrayList();
      public static int count;

      here term is the variable wich contains the actual value of the word. now when user queries for a word i need to search all these terms and find out whether the term user wants exists or not.... i ve this word class sorted w.r.t the "term" variable so it means that i can apply binary search for finding the user query.....i m doing this by adding all the term variables of the class in an arraylist and then applying binary search over it....but the problem is that i need to know the index of the arraylist where the user's queried term exists.....and i dont know the way to find out the index :( i ve added the sample chunk of code here.....anyone plzz help

      //adding all the term variables of Terminology class to the allTerms ArrayList.......
      for(int i = 0; i < Terminology .count; i ++ )
      {
      allTerms.Add(word[i].term);
      }

      //queryList is the ArrayList that contains the pharase queried by the user in the form of //one string at one index
      for(int j = 0; j < queryList.Count; j ++)
      {
      if(allTerms.BinarySearch(queryList[j]) >= 0)
      {
      need to know the index of allTerms ArrayList.
      }
      }

      looking forward for help Regards,

      L Offline
      L Offline
      lmoelleb
      wrote on last edited by
      #2

      Ehh, BinarySearch returns the index. If it just indicated if the item was present or not it would have returned a bool. It is also worth noticing that in case the item is not found, the return value indicates the position the item should have been at if it was present (useful for inserting in the list after it is sorted). All of this is in the MSDN documentation.

      R 1 Reply Last reply
      0
      • L lmoelleb

        Ehh, BinarySearch returns the index. If it just indicated if the item was present or not it would have returned a bool. It is also worth noticing that in case the item is not found, the return value indicates the position the item should have been at if it was present (useful for inserting in the list after it is sorted). All of this is in the MSDN documentation.

        R Offline
        R Offline
        Rizwan Rathore
        wrote on last edited by
        #3

        i really thought that it just returns a bool value....now i understand a little bit....but it wud b really helpful if u illustrate it with a little example thxx in advance regards,

        L 1 Reply Last reply
        0
        • R Rizwan Rathore

          i really thought that it just returns a bool value....now i understand a little bit....but it wud b really helpful if u illustrate it with a little example thxx in advance regards,

          L Offline
          L Offline
          lmoelleb
          wrote on last edited by
          #4

          Did you look at MSDN[^] as I wrote? Always look in MSDN first - it is the official documentation for the .NET Framework, and it contains a decent amount of samples.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups