Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java Block Lookup method

2024-05-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use the Java block search method". In the operation of the actual case, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The topic uses the block search method to find the ordered table, and the number of ordered tables is 15, which requires the user to input the elements of the ordered table, and the program outputs the search results. If successful, it shows the location of the elements in the ordered table.

1. Program analysis

Step1 first selects the largest keywords in each block to form an index table.

Step2 lookup is divided into two parts: first, a binary search or sequential search is performed on the index table to determine which block the record is in; then, a sequential search is used in the determined block.

2. Program realization

/ * declare the block lookup function * / int block_search (int iKey,int iArr []); / * define the structure of the block * / struct index {int iKey; / / keyword int iStart; / / start position int iEnd; / / end position} index_table [4] / / structure array / * * function name: block_search* parameter description: keyword of iKey query * array saved by iArr ordered array * description: block search * * * / int block_search (int iKey Int iArr []) {int I = 1 Magi j While (I

< 4) && (iKey >

Index_ table [I] .iKey) / / determine the block in which the element to be looked up is in {iStart;} if (I > 3) / / when the maximum number of blocks is greater than 0 {return 0;} else {j = index_ table [I] .iStart is returned. / / j is the starting position of the block range while ((j index_ table [I] .iEnd) / / beyond the range of the block {return 0;} return j;}} void main (void) {int iMagnej = 0pr iRetjournal iKeyReciArr [16]; printf ("Please enter 15 ordered numbers:"); for (I = 1 x I < 16) Scanf ("% d", & iArr [I]); for (I = 0 [I "< 3 + iStart) {index_ table [I] .iStart = j + 1; / determine the start position of each block range j = j + 1; index_ table [I] .iEnd = j + 4; / / determine the end position of each block range j = j + 4 Index_ table [I] .iKey = iArr [j]; / determine the maximum value of each block range element} printf ("Please enter the number you want to query:"); scanf ("% d", & iKey); iRet = block_search (iKey,iArr); if (iRet! = 0) printf ("found successfully, its location is:% d\ n", iRet); elseprintf ("find failed!\ n");}

3. Display the results

This is the end of the content of "how to use the Java block search method". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report