C++: Binary Search Part of a String -


Now I am on part 4 of my homework, I am trying to explain how the binary search only first 14 Two ccv files were given to an array of strings from letters:

01110011100110 is a simulated barcode.

Inventory. How: Inventory items are divided by commas - Barcode, Product, Price First Five Rows:

  01001010100011, Air Freshener, 12.43 01101000111101, Alfredo Sauce , 10.71 10000010100101, All spices, 4.14 00011011001111, Allergy medication, 20.06 00101010111011, Aluminum foil, 8.92   

Carts.csv: The first five rows containing a barcode of purchase of 'carriage':

  01000011010100,00010011010100 00110111100000 0010011010000001011000110111010111010001100101110100000001010001100101110101000000010101001000001001111010110010100100111111010100100101010 I am working on part 4 of homework: Part 4: Write a function to read in the Carts.csv file. Read and process it in one row at a time. Process steps are: Separate the barcode in each carton based on A comma delimiter. B. For each barcode, see the barcode in the product list. C. Remove the value from the product string data line and add to the running total for the cart. D. After processing the line, produce the total value for the cart. E. Repeat from phase (A) to end of file.  

When I try to return it, it is comparing the whole line instead of its exact part. How do binary search just one part of the string? Here is the part of my code:

  int binarySearch (string * list, integer size, string value) {int first = 0, final = size - 1, middle, position = -1; Bull got = wrong; While (! Found & amp; first & lt; = final) {middle = (first + last) / 2; If (list [middle] .comparare (value) == 0) {found = true; Position = center; } Else if (list [middle] .comparare (value)> 0) final = medium - 1; else first = middle + 1; } Return Status; } Zero process file (string filename, string * list, integer size) {ifstream file (filename); String line; Int count = 1; If (file.is_open ()) {while (! File.eof ()) {int ctr = 0; Int start = 0; Gateline (file, line); String substrings = ""; int find = line.find (COMMA); Cout & lt; & Lt; "Cart" & lt; & Lt; Count & lt; & Lt; ":"; While (search! = String :: NPO) {substring = line.substr (start, search - start); Int position = binary search (list, size, sub-base); Cout & lt; & Lt; Status & lt; & Lt; ""; Start = find + 1; CTR ++; Find = line.find (COMMA, start); } If (ctr> 0+ find == -1) {substring = line.substr (start, line.length () - start); int position = binary search (list, size, sub-base); Cout & lt; & Lt; Status & lt; & Lt; Endl; Count ++; }}} File.close (); }    

Try to fulfill the following function

  int binary search (const std :: string * list, int size, std :: string value) {int position = -1; int first = 0, final = size - 1; While (first & lt; = final) {int middle = (first + last) / 2; Int results = list [middle] .substr (0, value.size ()) .compare (value); If (result == 0) {position = middle; break; } And if (Results> 0) {Final = Medium - 1; } else {first = middle + 1; }} Return Status; }   

Of course the array list should be sorted according to the barcode in ascending order.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -