Binary search in files

Is there a way of executa a binary search directlly over a file ? a java native way ?

That would work best with a RandomAccessFile, since a binary search jumps back and forth looking at different places in the search space. And it would have to be a RandomAccessFile with fixed record lengths, sorted in the correct sequence. There is no method in the standard API to do that, but you could write the binary search code without much difficulty.

Similar Messages

  • Searching a binary search tree  written to a file

    hello
    I have a binary search tree which has 10 levels. Now I want to search a node
    after writing all the nodes to a file.
    Can anyone help me in doing this. A sample code would be great ...
    Thanks
    K

    You suggest that I do away with the inner class
    then?Absolutely. In fact I strongly suggest this. You are learning how to code and need to do things cleanly and in small steps. That means first creating your Node class and making sure it works. Then creating your Tree class, and making sure it works. In fact I would load the Strings into the Tree class first directly and testing things before even thinking about reading to and from files. Only then should you implement the file input and output steps.
    The key here is that you don't go on to the next step until you're reasonably sure that your current code works. Remember, it's MUCH easier to code than to debug.

  • Binary search tree - writing to a file in alphabetic order words from tree

    Hi
    I have written a program that will read a list of words from a file, insert these into a binary search tree, write words from the tree to another file, so that the resulting list contains words in ascending order. My input file Alpha1.txt contains the following contents in the order and format given (one word per line):
    Dawn
    Dave
    Mike
    Beth     
    David
    Gina
    Pat
    Cindy
    Sue
    My program is supposed to be producing an alphabetical list of these words in another file "final.txt".
    Instead it gives me the following list:
    Dave Beth David Gina Cindy Sue Pat Mike Dawn
    This is obviously wrong, right? My correct list in "final.txt" should be
    Beth Cindy Dave David Dawn Gina Mike Pat Sue
    I am not sure what is wrong with my code which I reproduce below:
    import java.io.*;
    import java.util.*;
    //read Java Developer's Almanac from exampledepot.com
    //Read this: http://en.wikipedia.org/wiki/Tree_traversal
    /**preorder(node)
      print node.value
      if node.left  ? null then preorder(node.left)
      if node.right ? null then preorder(node.right)
    public class AlphabeticBinarySortTree
         private static TreeNode root;
         private static TreeNode runner;
         static String[] alphaArray;
         static int alphaCounter;
         private static TreeNode alphaRunner;
         //Inner class
              private static class TreeNode
                   String word;
                   TreeNode left;
                   TreeNode right;
                   int count;
                   public TreeNode(String word)
                        this.word = word;
                        left = null;
                        right = null;
                   public void insertAll(TreeNode newNode)
                        if(newNode.word.compareTo(runner.word) < 1)
                             System.out.println("newNode.word = " + newNode.word);
                             if(runner.left == null)
                                  runner.left = newNode;
                                  runner = runner.left;
                             else
                                  insertAll(newNode);
                        else if(newNode.word.compareTo(runner.word) > 1)
                             System.out.println("newNode.word = " + newNode.word);
                             if(runner.right == null)
                                  runner.right = newNode;
                                  runner = runner.right;
                             else
                                  insertAll(newNode);
                        else
                             count++;
                   }// end method insertAll
                   // Recursively print words (with counts) in sorted order
                     public static void printInPreOrder(TreeNode root)
                             System.out.println(root.word + " ");
                             if(root.left != null)
                                   printInPreOrder(root.left);
                              if(root.right != null)
                                   printInPreOrder(root.right);
                       } //end method printInPreOrder()
                     //called from inside main
                    public static void arrangeInAscendingOrder(TreeNode root, PrintWriter pWriter)
                             if(root.left != null)
                                   arrangeInAscendingOrder(root.left, pWriter);
                             System.out.println();
                             System.out.println();
                             System.out.println(root.word + " ");
                             pWriter.write(root.word + " ");
                             if(root.right != null)
                                  arrangeInAscendingOrder(root.right, pWriter);
              }//end inner class TreeNode
         public AlphabeticBinarySortTree()
              root = null;
         //belong to the outer class
         public static void main(String[] args)
              System.out.println("This program reads text from a file that it will parse. ");
              System.out.println("In doing so, it will eliminate duplicate strings and ");
              System.out.println("pick up only unique strings.These strings will be in a ");
              System.out.println("stored in alphabetical order in a binary Search tree before they are ");
              System.out.println("written out to another text file in alphabetic order");
              //open the file for reading
              try
                   BufferedReader bReader = new BufferedReader(new FileReader("Alpha1.txt"));
                   String words;
                   int count;
                   //System.out.println("A test to inspect the contents of words: " + words);
                   //System.out.println("Words =" + words);
                   count = 0;
                   //why is there an endless loop when
                   //I use "while(str != null)
                   StringTokenizer st;
                   st = null;
                   //based on http://www.exampledepot.com/egs/java.io/ReadLinesFromFile.html
                   while ((words = bReader.readLine()) != null)
                        st = new StringTokenizer(words);
                       while(st.hasMoreTokens())
                            //shiffman.net/teaching/a2z/concordance
                            String token = st.nextToken();
                            System.out.println("Token = " +token);
                            AlphabeticBinarySortTree.initiateInsert(token);
                            //count the number of tokens in the string
                            count++;
                        }//end inner while
                   }//end outer while
                   System.out.println("Here are the contents of your tree:");
                   //System.out.println("before the call to print()");
                   print();
                   System.out.println("the no of words in the file is: " + count);
                   bReader.close();
              }//end of try
              catch(IOException exception)
                   exception.printStackTrace();
                   /**try
                             FileWriter fWriter = new FileWriter("final.txt");
                             BufferedWriter bWriter = new BufferedWriter(fWriter);
                             PrintWriter pWriter = new PrintWriter(bWriter);
                   catch(IOExcepion exception)
                        exception.printStackTrace();
         } // end main here
         //this method belongs to the outer class
         static void initiateInsert(String word)
              //TreeNode is also static by the way
              TreeNode newNode = new TreeNode(word);
              if(root == null)
                   root = newNode;
                   System.out.println("root.word = " + root.word);
                   runner = root;
              else
                   runner.insertAll(newNode);
         // Start the recursive traversing of the tree
            //without the access specifier 'static'
            //I would get the following error message
            //AlphabeticBinarySortTree.java:119: non-static method print() cannot be referenced from a static context
            public static void print()
                //System.out.println("**********AM I INSIDE THE PRINT() METHOD? ********");
               if (root != null)
                    //System.out.println("++++++++ AM I INSIDE THE IF BLOCK OF THE PRINT() METHOD? +++++++");
                    //System.out.println("Inside THE IF BLOCK OF print() BUT BEFORE THE CALL TO printInPreOrder(),root.word = " + root.word);
                  AlphabeticBinarySortTree.TreeNode.printInPreOrder(root);
                  //open the file for writing
                              try
                                             FileWriter fWriter = new FileWriter("final.txt");
                                             BufferedWriter bWriter = new BufferedWriter(fWriter);
                                             PrintWriter pWriter = new PrintWriter(bWriter);
                                             AlphabeticBinarySortTree.TreeNode.arrangeInAscendingOrder(root, pWriter);
                                          pWriter.close();
                              catch(IOException eException)
                                   eException.printStackTrace();
               }//end of if block
            } // end of method print
    }//end outer enclosing class here--------
    All help is highly appreciated. Thanks for your time and consideration.

    You suggest that I do away with the inner class
    then?Absolutely. In fact I strongly suggest this. You are learning how to code and need to do things cleanly and in small steps. That means first creating your Node class and making sure it works. Then creating your Tree class, and making sure it works. In fact I would load the Strings into the Tree class first directly and testing things before even thinking about reading to and from files. Only then should you implement the file input and output steps.
    The key here is that you don't go on to the next step until you're reasonably sure that your current code works. Remember, it's MUCH easier to code than to debug.

  • Binary search in text files

    Hi all,
    I'm thinking about how to implement a binary sort to get,given a key, a value from a text file with a list of words in order. I saw randomaccessfile for j2se and I know that this work it's usually done by seek functions but how to do the seek work without the File class , with only the InputStream and Reader? I'm talking about the j2me midp 2 cldc 1.1 api, is there some methods or class to use for this thing? How could be implemented a binary search in a text file resident in the /res dir or the JAR or which could be the problems that cannot make possible this staff? If there was something like seek one way could be that one of decide a common length of words to read so going to the half of the text file it's possible with simply multiplication, and the do the binary search things.But for now I haven't found any resources or help.
    I hope you can help me to understand, thank you

    Hallo all,
    it is NOT the problem to locate the text I need to find in the fmb, or fmx.
    The problem is that since I want to change not only the text but also some more code around I want to do this in Form Builder - Object Navigator. And I'm not able to discover in which trigger or procedure the text appears.
    I do not want to edit fmx, or fmb in a text editor because I suupose theer are some checksums hidden for the format.
    -duro
    BTW in FMT there is no code seen (only some binary) for v6i as it was in v4.5.

  • Binary search in a text file.

    Is it possible to carry out binary search directly in the text file without passing the file data into a List data, in order to save RAM?

    If the file is sorted, and if you know what byte position each record begins at, then, yes, using RandomAccessFile you can do this.
    I don't know if it's really the best approach though. If the file's not all that big, or if the relevant parts of its content can be represented in more compact form, then sorting in memory will be simpler and quicker.

  • [svn:osmf:] 11361: Adding a generic binary search utility ( updating project file).

    Revision: 11361
    Author:   [email protected]
    Date:     2009-11-02 05:21:35 -0800 (Mon, 02 Nov 2009)
    Log Message:
    Adding a generic binary search utility (updating project file).
    Modified Paths:
        osmf/trunk/framework/MediaFramework/.flexLibProperties

    Hi,
    try this forum: WebCenter Portal
    Frank

  • Problem with binary search tree

    Hi all, just having troubles with a program im writing.
    My program is based on a binary search tree full of items which are passed in via an input file and then saved to an output file.
    I have written a sellItem method which gets passed in the item and quantity that has been sold which then needs to be changed in the binary tree.
    Here if my sell Item method:
        public void sellItem(Item item, int quantity){
            stockItem = item;
            mQuantity = quantity;
            if (tree.includes(stockItem)){
                int tempQuantity = stockItem.getQuantityInStock();
                tempQuantity -= mQuantity;
            else{
                throw new IllegalArgumentException("The Barcode " + mBarCode + " does NOT exist.");
        }and here is where i am calling it in a test class :
    number1.sellItem(item1, 40);Each item is in this format :
    ABCD, PENCIL, 1, 0.35, 200, 100, 200
    where 200 is the quantity.
    Therefore if i pass 40 into the method the binary search tree should then store the quantity as 160.
    below is a copy of my binary tree :
    public class BSTree extends Object {
        private class TreeNode extends Object{
            public Comparable data;
            public TreeNode left;
            public TreeNode right;
            public TreeNode() {
                this(null);
            public TreeNode(Comparable barCode){
                super();
                data = barCode;
                left = null;
                right = null;
        private TreeNode root; 
        private int nodeCount;
        public BSTree(){
            super();
            root = null;
            nodeCount = 0;
        public boolean isEmpty() {
          return root == null;
        public int size() {
          return nodeCount;
        private TreeNode attach(TreeNode newPointer, TreeNode pointer){
            if (pointer == null){
                nodeCount++;
                return newPointer;
            else {
                Comparable obj1 = (Comparable) newPointer.data;
                Comparable obj2 = (Comparable) pointer.data;
            if (obj1.compareTo(obj2) < 0) //Go left
                pointer.left = attach(newPointer, pointer.left);
            else //Go right
                pointer.right = attach(newPointer, pointer.right);
            return pointer;
        public void insert(Comparable item){
            //Create a new node and initialize
            TreeNode newPointer = new TreeNode(item);
            //Attach it to the tree
            root = attach(newPointer, root);
        public Comparable remove(Comparable key) {
            TreeNode pointer;
            TreeNode parent;
            //Find the node to be removed
            parent = null;
            pointer = root;
            while ((pointer != null) && !key.equals(pointer.data)) {
                parent = pointer;
                if (key.compareTo(pointer.data) <0)
                    pointer = pointer.left;
                else
                    pointer = pointer.right;
            if (pointer == null)
                return null;
            //Orphans
            TreeNode leftSubtree = pointer.left;
            TreeNode rightSubtree = pointer.right;
            if (parent == null)
                root = null;
            else if (key.compareTo(parent.data) < 0)
                parent.left = null;
            else
                parent.right = null;
            //Reattaching any orphans in the left subtree
            if (leftSubtree != null) {
                root = attach(leftSubtree, root);
                nodeCount--;
            //Reattaching any orphans in the right subtree
            if (rightSubtree != null) {
                root = attach(rightSubtree, root);
                nodeCount--;
            nodeCount--;
            return pointer.data;
        private TreeNode search(TreeNode pointer, Comparable key) {
            if (pointer == null)
                return null;
            else if (pointer.data.compareTo(key) == 0)
                return pointer;
            else if (key.compareTo(pointer.data) < 0)
                return search(pointer.left, key);
            else
                return search(pointer.right, key);
        public boolean includes(Comparable key) {
            return (search(root, key) != null);
        public Comparable retrieve(Comparable key) {
            TreeNode pointer;
            pointer = search(root, key);
            if (pointer == null)
                return null;
            else
                return pointer.data;
        public Comparable[] getAllInOrder() {
            Comparable[] list = new Comparable[nodeCount];
            inOrderVisit(root,list,0);
            return list;
        private int inOrderVisit(TreeNode pointer, Comparable[] list, int count) {
            if (pointer != null) {
                count = inOrderVisit(pointer.left, list, count);
                list[count++] = pointer.data;
                count = inOrderVisit(pointer.right, list, count);
            return count;
        public String toString() {
            StringBuffer result = new StringBuffer(100);
            inOrderString(root, result);
            return result.toString();
        private void inOrderString(TreeNode pointer, StringBuffer result) {
            if (pointer != null) {
                inOrderString(pointer.left, result);
                result.append(pointer.data.toString() + "\n");
                inOrderString(pointer.right, result);
    }Thanks for everyones help. Keep in mind i'm very new to java.

    Hi all, just having troubles with a program im writing.
    My program is based on a binary search tree full of items which are passed in via an input file and then saved to an output file.
    I have written a sellItem method which gets passed in the item and quantity that has been sold which then needs to be changed in the binary tree.
    Here if my sell Item method:
        public void sellItem(Item item, int quantity){
            stockItem = item;
            mQuantity = quantity;
            if (tree.includes(stockItem)){
                int tempQuantity = stockItem.getQuantityInStock();
                tempQuantity -= mQuantity;
            else{
                throw new IllegalArgumentException("The Barcode " + mBarCode + " does NOT exist.");
        }and here is where i am calling it in a test class :
    number1.sellItem(item1, 40);Each item is in this format :
    ABCD, PENCIL, 1, 0.35, 200, 100, 200
    where 200 is the quantity.
    Therefore if i pass 40 into the method the binary search tree should then store the quantity as 160.
    below is a copy of my binary tree :
    public class BSTree extends Object {
        private class TreeNode extends Object{
            public Comparable data;
            public TreeNode left;
            public TreeNode right;
            public TreeNode() {
                this(null);
            public TreeNode(Comparable barCode){
                super();
                data = barCode;
                left = null;
                right = null;
        private TreeNode root; 
        private int nodeCount;
        public BSTree(){
            super();
            root = null;
            nodeCount = 0;
        public boolean isEmpty() {
          return root == null;
        public int size() {
          return nodeCount;
        private TreeNode attach(TreeNode newPointer, TreeNode pointer){
            if (pointer == null){
                nodeCount++;
                return newPointer;
            else {
                Comparable obj1 = (Comparable) newPointer.data;
                Comparable obj2 = (Comparable) pointer.data;
            if (obj1.compareTo(obj2) < 0) //Go left
                pointer.left = attach(newPointer, pointer.left);
            else //Go right
                pointer.right = attach(newPointer, pointer.right);
            return pointer;
        public void insert(Comparable item){
            //Create a new node and initialize
            TreeNode newPointer = new TreeNode(item);
            //Attach it to the tree
            root = attach(newPointer, root);
        public Comparable remove(Comparable key) {
            TreeNode pointer;
            TreeNode parent;
            //Find the node to be removed
            parent = null;
            pointer = root;
            while ((pointer != null) && !key.equals(pointer.data)) {
                parent = pointer;
                if (key.compareTo(pointer.data) <0)
                    pointer = pointer.left;
                else
                    pointer = pointer.right;
            if (pointer == null)
                return null;
            //Orphans
            TreeNode leftSubtree = pointer.left;
            TreeNode rightSubtree = pointer.right;
            if (parent == null)
                root = null;
            else if (key.compareTo(parent.data) < 0)
                parent.left = null;
            else
                parent.right = null;
            //Reattaching any orphans in the left subtree
            if (leftSubtree != null) {
                root = attach(leftSubtree, root);
                nodeCount--;
            //Reattaching any orphans in the right subtree
            if (rightSubtree != null) {
                root = attach(rightSubtree, root);
                nodeCount--;
            nodeCount--;
            return pointer.data;
        private TreeNode search(TreeNode pointer, Comparable key) {
            if (pointer == null)
                return null;
            else if (pointer.data.compareTo(key) == 0)
                return pointer;
            else if (key.compareTo(pointer.data) < 0)
                return search(pointer.left, key);
            else
                return search(pointer.right, key);
        public boolean includes(Comparable key) {
            return (search(root, key) != null);
        public Comparable retrieve(Comparable key) {
            TreeNode pointer;
            pointer = search(root, key);
            if (pointer == null)
                return null;
            else
                return pointer.data;
        public Comparable[] getAllInOrder() {
            Comparable[] list = new Comparable[nodeCount];
            inOrderVisit(root,list,0);
            return list;
        private int inOrderVisit(TreeNode pointer, Comparable[] list, int count) {
            if (pointer != null) {
                count = inOrderVisit(pointer.left, list, count);
                list[count++] = pointer.data;
                count = inOrderVisit(pointer.right, list, count);
            return count;
        public String toString() {
            StringBuffer result = new StringBuffer(100);
            inOrderString(root, result);
            return result.toString();
        private void inOrderString(TreeNode pointer, StringBuffer result) {
            if (pointer != null) {
                inOrderString(pointer.left, result);
                result.append(pointer.data.toString() + "\n");
                inOrderString(pointer.right, result);
    }Thanks for everyones help. Keep in mind i'm very new to java.

  • Storing strings in binary search tree

    On the below code I get: ClassCastException : java.lang.String . I am trying to build a binary search tree from a text file one word at a time. when I call this method below the first time it works fine, but on the second call it gets the error at the second if statement:
    getInfo() returns a String
        public void insertBST(Object o) {
            TreeNode p, q;
            TreeNode r = new TreeNode(o);
            if (root == null)
                root = r;
            else {
                p = root;
                q = root;
                while (q != null) {
                    p = q;
                    System.out.println(r.getInfo());
                    if (((TreeComparable)(r.getInfo())).compareTo((TreeComparable)(p.getInfo())) < 0)
                        q = p.getLeft();
                    else
                        q = p.getRight();
                if (((TreeComparable)(r.getInfo())).compareTo((TreeComparable)(p.getInfo())) < 0)
                    setLeftChild(p, r);
                else
                    setRightChild(p, r);               
       }------------ This is the code I use to call on the above function:
    public void readFromFile() {
            //int i = 1;
            while (fileScan.hasNext()) {
                    String buf = fileScan.next();
                   hash(buf);
                  if (table[tableIndex] == tableIndex) {
                     System.out.println("Same Omitted Word");
                    else{
                        obt.insertBST(buf);
                        System.out.println("Not an Omitted Word");
    public int hash(String s) {
                    sum = 0;
                        for(int i = 0; i< s.length(); i++)
                            sum += (int)s.charAt(i);
                        tableIndex = sum%TABLESIZE;
                            return tableIndex;
    -------------------Also, this interface is used by the insertBST function:
    public interface TreeComparable {
        public int compareTo(Object o);
        public void operate(Object o);
        public void visit();

    We got the inserBST() funtion from the instructor, it is in a ObjectBinaryTree class we should use to build the tree, also we received the TreeComparable interface which inserBST() uses from the instructor.
    One one part of the assigment it says"
    Note that while the TreeNode class is built to hold a generic Object, you'll be creating a Word class whose objects will be placed in the TreeNode's of the Binar search tree. Each Word object should provide the followinf fields:
    a reference to the word, an int to count the nomber of times it apears.
    Which I have not done, I'm simply passing the String as I read it from the file.
    Now, I'm thinking TreeComparable is acting as an Int object and is trying to cast a String which produces the error.
    Also, I have used this where the inserBST():
    public class ObjectBinaryTree implements TreeComparable {
    but then I get a message that it cant override one of the methods in TreeComparable.
    This is the rest of the class I'm using to implement the ObjectBinayTree class.
    public void readFromFile() {
            //int i = 1;
            while (fileScan.hasNext()) {
                    String buf = fileScan.next();
                    // System.out.println(buf);
                   hash(buf);
                   // System.out.println(tableIndex);
                  if (table[tableIndex] == tableIndex) {
                     //System.out.println("Same Omitted Word");
                    else{
                        //obt.insertBST(buf);
                        //System.out.println("Not an Omitted Word");
         public void makeHashTable() {
                    while (fileScan.hasNext()) {
                        String buf = fileScan.next();
                        hash(buf);
                        if (table[tableIndex] == 0)
                            table[tableIndex] = sum%TABLESIZE;
                    else{
                        do{
                            tableIndex++;
                    }while( table[tableIndex] != 0);
                            table[tableIndex] = sum % TABLESIZE;
                public int hash(String s) {
                    sum = 0;
                        for(int i = 0; i< s.length(); i++)
                            sum += (int)s.charAt(i);
                        tableIndex = sum%TABLESIZE;
                            return tableIndex;
         }

  • Linear and Binary Searching of Parallel Arrays

    I'm an AP student who used the "Fundamentals of Java" by Lambert/Osborne 3rd Edition. This text book has code that doesn't match anything else I've found in other how-to's, guides, or teach yourself books. Not even online can I find code that matches up with the format used in this book!
    I've got an assignment that wants me to read in a 4 digit account number of N number of customers, places them in two parallel arrays. Data found in two separate txt files. Create a prompt that ask's for customer's account number then displays account balance. Same program for both linear and binary search methods (2 programs).
    I know the search method and how to read the files with a scanner. It is the body of the program that is stumping me. How to call and search the arrays themselves. Any help would be great.

    First of all, you have posted this question in the wrong place. Please post these kinds of general questions in the New to Java forum.
    Second, if you're in an AP class, don't you have a teacher you can ask?
    But anyway, here's the idea
    For a linear search, you go thru the array element by element, and on each element you call equals(x) to see if that element is equal to what you're searching for (note that primitives use == rather than equals)
    For binary search, note first of all that your data MUST BE COMPARABLE (primative or implement the comparable interface) and MUST BE SORTED.
    Then what you can do if go to the middle of the list, and if what you are searching for is less than that element, go to the middle of the first half of the list (if it's greater, go the the middle of the upper half of the list) and keep breaking the list in half until you've found the element or you know its not there.

  • How does sy-tabix affect by binary search transforming no fields?

    1 report ztx1110.
         2 data: begin of it occurs 3,
         3           f1(2) type n,
         4           f2    type i,
         5           f3(2) type c,
         6           f4    type p,
         7           end of it.
         8
         9   it-f1 = '40'. it-f3 = 'DD'. it-f2 = it-f4 = 4. append it.
        10  it-f1 = '20'. it-f3 = 'BB'. it-f2 = it-f4 = 2. append it.
        11
        12 sort it by f1.
        13 do 5 times.
        14     it-f1 = sy-index * 10.
        15     it-f3 = 'XX'.
        16     it-f2 = it-f4 = sy-index.
        17     read table it
        18         with key f1 = it-f1
        19         binary search
        20         transporting no fields.
        21     if sy-subrc <> 0.
        22         insert it index sy-tabix.
        23         endif.
        24     enddo.
        25
        26 loop at it.
        27     write: / it-f1, it-f2, it-f3, it-f4.
        28     endloop.
    in this program changing value of sy-tabix as such sy-index.
    means in it's first loop it's value is 1, on second loop it's 2, and so on up to 5.
    okay that is due to binary search.
    but why binary search affecting this system variable?

    Hi Vinay,
    It is simple.
    This depends on your select query. 
    CASE 1: If you use select ..into table.....,  then there wil be nothing in your header ls_vbap. Now if you execute READ stmt..you will get nothing.
    CASE 2: If you use Select..... into ls_vbap.....append ls_vbap....clear ls_vbap.....endselect.   In this case also the output of READ will be nothing because you are clearing header.  So while READ stmt you are comparing ls_vbap-vbeln and ls_vbap-posnr , as nothing in it you will get nothing
    CASE 3: If you use case 2 without CLEAR stmt then always you will get the index of the last fetched record...i.e., the last record of the internal table before sorting..
    I think it is helpful for you....if you are not clear just reply me

  • Binary Search need clarification

    Hi All,
      I am facing a problem here in binary search. I will try to explain the situation with an example.
    Internal table : it_vbap
    Fields :  vbeln   posnr   qty
    Index 1  100      10       5
    index 2  100      10       5
    index 3  100      20       5
    index 4  100      20       5
    index 5  100      30       5
    index 6  100      30      5
    the abap code is this.
    sort it_vbap by vbeln posnr.
    read table it_vbap into ls_vbap with ket
                   vbeln  = ls_vbap-vbeln
                   psonr = ls_vbap-posnr
                   binary search.
    If sy-subrc  = 0.
    write : 'index :' sy-tabix.
    endif.
    My question here is does it always write index 1,3,5 (means in the all the case it should return the first record  ), otherwise it can also return 1, 3, 6.
    Pay attendtion the posnr are the same for every two records.
    The internal table not only contains 6 six records , my question was however not depends on the number of records in the internal table, the binary search will return the first sorted key record in the table or not.
    Please post your views.
    Thanks & regards,
    Vijay

    Hi Vinay,
    It is simple.
    This depends on your select query. 
    CASE 1: If you use select ..into table.....,  then there wil be nothing in your header ls_vbap. Now if you execute READ stmt..you will get nothing.
    CASE 2: If you use Select..... into ls_vbap.....append ls_vbap....clear ls_vbap.....endselect.   In this case also the output of READ will be nothing because you are clearing header.  So while READ stmt you are comparing ls_vbap-vbeln and ls_vbap-posnr , as nothing in it you will get nothing
    CASE 3: If you use case 2 without CLEAR stmt then always you will get the index of the last fetched record...i.e., the last record of the internal table before sorting..
    I think it is helpful for you....if you are not clear just reply me

  • Search Remote Files... or ...How Do I Delete All of My LCK Files?

    hey everyone.
    i need to delete a bunch of .LCK files from my server so
    Dreamweaver
    will stop telling me someone else has stuff checked-out and
    that i need
    to enable blah blah blah. i can't just check everything in
    because A.
    that would take forever and B. the "person" who has them
    checked out is
    actually me, from a previous site definition that is now gone
    because i
    had to recreate it.
    unless i'm missing something (and i've been spending some
    time looking
    for it), there doesn't seem to be a way in Dreamweaver (at
    least in
    version 8, which is what i have) to search for files on the
    remote view.
    and even if there was, it doesn't look like the remote view
    displays
    hidden files, i.e. .LCK files.
    my server control panel does give me the option to search for
    files
    using the file manager, but it only searches the folder you
    have
    selected, and no sub-folders. there are hundreds, maybe
    thousands of
    folders on this thing, and it would really take a long time
    to click on
    each and every folder, search for the .lck files, and then
    delete them.
    so, my question is, what would be the best/easiest way to
    find and
    delete .lck files (or really, any file for that matter) on
    the remote
    server?
    thanks!

    i do NOT want check-in/check-out enabled. i'm trying to get
    rid of it
    altogether, but i tried selecting the checked out files to
    check them
    back in, and it said there were none.
    there is no "unlock" option, so i guess i need to pick check
    in. but
    here's my question, since it's this other instance of "me"
    that has them
    checked out, will this work? it's not recognizing me or my
    computer or
    whatever as the person who has them checked out. i think it's
    because i
    had to recreate my site definition about a week ago or so,
    and i deleted
    the old one. so it's like a user that no longer exists has
    them checked out.
    Alan wrote:
    > Do you want checkin/checkout to still be enabled when
    this is done?
    >
    > try this or a variation of it-
    >
    > in the Files Panel, right-click on the root site folder
    and pick checkin. Or
    > unlock.
    >
    >

  • How to search a file from a hierarchy and delete it

    hi ,
    i have to delete a file from a directory structure .i dno't know where is file stored in my folder hierarchy .i have to search that file and delete that file .
    for example ;
    i have a folder name A , which have folder B ,C ,D ,E . B folder have other 2 folder or 3 file (anything) , same C and D And E can have file or folder .
    means we dnot know that A folder have how many files or folder in it . in that we have to search a specific file and delete it .

    hi vineet ,
    this is only for u .
    here is my code
    class serDir
         public static void main(String[] args)
              String dirname="/java";
              File f1=new File(dirname);
              if(f1.isDirectory()){
                   System.out.println("directory name "+dirname);
                   String s[]=f1.list();
              for(int i=0;i<s.lenght();i++){
              File f=new(dirname +"/"+ s);
              if(f.isDirectory()){
    System.out.println("directory name "+s[i]);
                   } else {
                   System.out.println("file name "+s[i]);
              } else {
              System.out.println(dirname+"is not directory" );
    but not working properly , now plz tell me what changes i should make to full fill my requirement . question is still same ....................waiting

  • Searching a file from structure and delete

    hi ,
    i have to delete a file from a directory structure .i dno't know where is file stored in my folder hierarchy .i have to search that file and delete that file .
    for example ;
    i have a folder name A , which have folder B ,C ,D ,E . B folder have other 2 folder or 3 file (anything) , same C and D And E can have file or folder .
    means we dnot know that A folder have how many files or folder in it . in that we have to search a specific file and delete it .

    Look at the HttpUnit extension for Junit (www.junit.org) for a great package for accessing and "parsing" http data.
    Or you could simple open a connection (via the URL class) and then do an indexOf or use a regular expression package (jakarta-oro is good one).

  • When looking at my "About This Mac" it says that I have 60gb of space left on my hard drive, but when I go into finder to find all of these files there is not 300gb worth in anything I search, even searching, "All files on the Mac". Help!?

    When looking at my "About This Mac" it says that I have 60gb of space left on my hard drive, but when I go into finder to find all of these files there is not 300gb worth in anything I search, even searching, "All files on the Mac". Help!?
    It says I have over 150 gigs of video on my hard drive. But I have gone through and deleted almost all of what shows up, still it says there is roughly the same amount on the hard drive. Where are these files? I want to delete them so I can have my hard drive clear.
    Thanks for your help guys!

    Quote from the article.
    Time Machine in OS X Lion includes a new feature called "local snapshots" that keeps copies of files you create, modify or delete on your internal disk. Local snapshots compliment regular Time Machine backups (that are stored on your external disk or Time Capsule) giving you a "safety net" for times when you might be away from your external backup disk or Time Capsule and accidentally delete a file.
    So what makes a notebook any different then a desktop, other then with a desktop you might have your tm backup drive connected all the time.
    The object here is to not indiscriminately delete files you need or want to keep. I personally have never deleted a file I wanted to keep.
    In essence a backup is for catastrophic failure of your system. So it can be restored once that failure has been fixed. Not because you go in willy nilly and start deleting files.

Maybe you are looking for

  • How do I add songs to my iTunes Store wish list on my iPod?

    How do I add a song to my iTunes wish list on my iPod? I keep looking up songs/albums I want to buy on my iPod Touch, but I can never add them to a wish list because I can't find the right button to push. I know the button is next to the price on the

  • Node question

    I'm thinking of purchasing a Mac mini to use as a node computer for Logic Pro 8. Before I can do that, however, I need to install the Logic node on the mac mini and put this in the startup items so the node loads automatically when the Mac mini boots

  • Mac pro monitor has a shadow in its center. Does anybody know what can cause that?

    Last day my mac pro showed a shadow in its display center. Does anybody know what can cause? I use to use it a litle, cause i'm new on macs and still use pc based on windows.

  • Sap SUS MM LIBRARY

    Hi experts, Kindly give me the link from where I can see the sus mm library (vendor portal) Thanks GR

  • Extracting Metadata into excel

    I have a large client that prints store signage. We have hundreds of signs in our Bridge portfolio for them and we want to verify that each sign has been created at the correct size. I've noticed that the Metadata for each file reveals it's size in i