Vehicle Service Management Model Algorithm

Source: Internet
Author: User

The vehicle service management model algorithm is implemented as follows:

# Include "Common. H "/********************************** constants and type Definition **********************************/# define max_num_of_key 7 // maximum number of keywords # define radix_n 10 // base number of decimal integers # define radix_c 26 // base number of 26 letters # define max_space 2000 // maximum linked list space # define lt (, b) (a) <(B) # define eq (A, B) (a) = (B) # define BG (A, B) (a)> (B) typedef char keystype; // key type typedef struct {char carname [15]; // vehicle Name char color [10]; // color char date [10]; // date of purchase char Ownername [15]; // owner} infotype; typedef struct {keystype keys [max_num_of_key]; // Keyword: infotype otheritems; // other data item int next;} slcell; typedef struct {slcell R [max_space]; // available space of the static linked list. R [0] is the header node int keynum; // The number of current keywords recorded int recnum; // current length of the static linked list} sllist; // type of the static linked list typedef int arrtype_n [radix_n]; // type of the decimal pointer array typedef int arrtype_c [radix_c]; // pointer array type with 26 letters /****************************** ******************************** * *******/Void initsllist (sllist & L) // initialize the linked list {L. recnum = 0; L. keynum = max_num_of_key;} // initsllistvoid getdata (sllist & L) // obtain data {keystype key = '0'; Int J = 1; cout <"Please input the car number with key = '#' to end" <Endl; cout <"Example: 01b3456" <Endl; cout <"Car number ="; for (INT I = 0; I <max_num_of_key; I ++) {CIN> key; if (I = 2 & Key> 'Z') Key = (char) (key-'A' + 'A'); L. R [1]. keys [I] = key;} printf ("carname:"); gets (L. R [1]. othe Ritems. carname); printf ("color:"); gets (L. R [1]. otheritems. color); printf ("Date:"); gets (L. R [1]. otheritems. date); printf ("ownername:"); gets (L. R [1]. otheritems. ownername); While (key! = '#') {J ++; cout <Endl <"Car number ="; for (INT I = 0; I <max_num_of_key; I ++) {CIN> key; if (I = 2 & Key> 'Z') Key = (char) (key-'A' + 'A '); if (Key = '#') {J --; break;} l. R [J]. keys [I] = key;} If (Key = '#') break; printf ("carname:"); gets (L. R [J]. otheritems. carname); printf ("color:"); gets (L. R [J]. otheritems. color); printf ("Date:"); gets (L. R [J]. otheritems. date); printf ("ownername:"); gets (L. R [J]. otheritems. ownername);} // whilel. recnum = J ;} // Getdataint ord_n (keystype key) // map the key keyword in the record to [0 .. radix_n] {return (INT) (key-'0');} // ord_nint ord_c (keystype key) // map the key keyword in the record to [0 .. radix_c] {return (INT) Key-'A');} // ord_cint succ (Int J) // evaluate the successor function {return (J + 1) of J;} // succvoid distribute_n (slcell * r, int I, arrtype_n & F, arrtype_n & E) // records in the r field of the static linked list l have been recorded by (Keys [0],... keys [I-1]) ordered // This algorithm creates a radix_n sub-table based on the I-th keyword keys [I, make the records of keys [I] In the same subtable the same // F [0 .. radix_n] and e [0.. Radix_n] points to one and the last records in the respective tables {Int J, P; For (j = 0; j <radix_n; j ++) // each sub-table is initialized as an empty table {f [J] = 0; E [J] = 0;} For (P = R [0]. next; P = R [p]. next) {J = ord_n (R [p]. keys [I]); If (! F [J]) f [J] = P; else R [E [J]. next = P; E [J] = P; // Insert the node referred to by p to the j subtable} // distribute_nvoid collect_n (slcell * r, int I, arrtype_n F, arrtype_n e) // This algorithm uses keys [I] to automatically remove F [0 .. the sub-tables specified by radix_n are linked to a linked list in sequence. // E [0 .. RADIX_n-1] for each sub-Table tail pointer {Int J, t; for (j = 0 ;! F [J]; j = succ (j); // find the first non-empty subtable R [0]. next = f [J]; t = E [J]; // R [0]. next points to a node in the first non-empty child table while (j <RADIX_n-1) {for (j = succ (j); j <RADIX_n-1 &&! F [J]; j = succ (j); // find the next non-empty subtable if (F [J]) {R [T]. next = f [J]; t = E [J];} // link two non-empty subtables} R [T]. next = 0; // t pointing to the last node in the last non-empty sub-Table} // collect_nvoid distribute_c (slcell * r, int I, arrtype_c & F, arrtype_c & E) // records in the r field of the static linked list l have been recorded by (Keys [0],... keys [I-1]) ordered // This algorithm creates a radix_c sub-table based on the I-th keyword keys [I, make the records of keys [I] In the same subtable the same // F [0 .. radix_c] and e [0 .. radix_c] points to one and the last records in the respective tables {Int J, P; For (j = 0; j <radix_c; j ++) // each sub-table is initialized as an empty table {f [J] = 0; E [J] = 0;} For (P = R [0]. next; P = R [p]. next) {J = Ord_c (R [p]. Keys [I]); If (! F [J]) f [J] = P; else R [E [J]. next = P; E [J] = P; // Insert the node referred to by p to the j subtable} // distribute_cvoid collect_c (slcell * r, int I, arrtype_c F, arrtype_c e) // This algorithm uses keys [I] to automatically remove F [0 .. the sub-tables specified by radix_c are linked to a linked list in sequence. // E [0 .. RADIX_c-1] for each sub-Table tail pointer {Int J, t; for (j = 0 ;! F [J]; j = succ (j); // find the first non-empty subtable R [0]. next = f [J]; t = E [J]; // R [0]. next points to a node in the first non-empty child table while (j <RADIX_c-1) {for (j = succ (j); j <RADIX_c-1 &&! F [J]; j = succ (j); // find the next non-empty subtable if (F [J]) {R [T]. next = f [J]; t = E [J];} // link two non-empty subtables} R [T]. next = 0; // T points to the last node in the last non-empty sub-Table} // collect_cvoid radixsort (sllist & L) // sorts the base, makes l an ordered static linked list {int I; arrtype_n FN, en; arrtype_c FC, EC; for (I = 0; I <L. recnum; I ++) L. R [I]. next = I + 1; L. R [L. recnum]. next = 0; // convert it to a static linked list for (I = L. keynum-1; I> 2; I --) // distribute and collect keywords in sequence by priority, because the keyword of the character must be separately distribute_n (L. r, I, FN, en); collect_n (L. r, I, FN, en);} di Stribute_c (L. r, 2, FC, EC); collect_c (L. r, 2, FC, EC); for (I = 1; I> = 0; I --) {distribute_n (L. r, I, FN, en); collect_n (L. r, I, FN, en) ;}// radixsortvoid arrange (sllist & L) // adjust the record position based on the pointer values of each node in the static linked list L, the records in L are non-decreasing by keywords {int I, p, q; slcell Buf; P = L. R [0]. next; // P indicates the current position of the first record for (I = 1; I <L. recnum; I ++) // L. R [1 .. i-1] is ordered by keyword {// the current position of the I-th record in l should be no less than Iwhile (P <I) P = L. R [p]. next; // locate the I-th record and use P to indicate its current position in L. Q = L. R [p]. next; // Q indicates if (P! = I) {Buf = L. R [p]; L. R [p] = L. R [I]; L. R [I] = Buf; // exchange Record L. R [I]. next = P; // point to the deleted record, which can be retrieved by the while loop in the future} p = Q; // P points to the end of the unadjusted table, prepare for the I + 1 record} // arrangevoid sllisttraverse (sllist L) // traverse the static table {int I, j; cout <Endl; cout <"carnum" <'\ t' <"carname" <' \ t' <"color" <'\ t' <"data" <<'\ t' <"ownername" <Endl; if (L. recnum) for (I = 1; I <= L. recnum; I ++) {for (j = 0; j <max_num_of_key; j ++) cout <L. R [I]. keys [J]; cout <'\ t' <L. R [I]. otheritems. carname <<'\ T' <L. R [I]. otheritems. color <'\ T'; cout <L. R [I]. otheritems. date <'\ t' <L. R [I]. otheritems. ownername <Endl;} // For} // sllisttraversevoid datatraverse (sllist L, int num) // display a record {Int J; cout <"(note: other data term is peculiarity character) "<Endl; cout <"carnum" <'\ t' <"carname" <' \ t' <"color" <'\ t' <"data" <<'\ t' <"ownername" <Endl; for (j = 0; j <max_num_of_key; j ++) cout <L. R [num]. keys [J]; cout <'\ t' <L. R [num]. otheritems. carname <'\ t' <L. R [num]. otheritems. carname <'\ T'; cout <L. R [num]. otheritems. date <'\ t' <L. R [num]. otheritems. ownername <Endl;} // datatraversevoid getsearchkey (keystype * Key) // obtain the keyword {cout <"Please input the key you want to search :"; for (INT I = 0; I <max_num_of_key; I ++) CIN> key [I]; If (Key [2]> 'Z ') key [2] = (char) (Key [2]-'A' + 'A');} // getsearchkeyvoid randdata (sllist & L) // randomly generate the license plate number, 20 will be randomly generated here 0 license plate numbers {int I, j; for (I = 1; I <= 200; I ++) {for (j = 0; j <max_num_of_key; j ++) {If (j = 0) L. R [I]. keys [0] = (char) (RAND () * 4/32768 + '0'); else {If (j = 1 & L. R [I]. keys [0] = '3') L. R [I]. keys [1] = '1'; else {If (j = 2) L. R [I]. keys [2] = (char) (RAND () * 26/32768 + 'A'); else l. R [I]. keys [J] = (char) (RAND () * 10/32768 + '0') ;}}} L. keynum = 7; L. recnum = 200;} // randdatavoid sllisttrarand (sllist L) // traverses the randomly generated static table {int I, j; If (L. recnum) for (I = 1; I <= L. recnum; I ++) {fo R (j = 0; j <max_num_of_key; j ++) cout <L. R [I]. keys [J]; cout <'\ T';} // For} // sllisttrarandbool equal (keystype key1 [], keystype key2 []) // judge equal {for (INT I = 0; I <max_num_of_key; I ++) {If (! Eq (key1 [I], key2 [I]) return false;} return true;} // define bool little (keystype key1 [], keystype key2 []) // smaller judgment {for (INT I = 0; I <max_num_of_key; I ++) {If (LT (key1 [I], key2 [I]) return true; else if (BG (key1 [I], key2 [I]) return false;} // littleint search_bin (sllist L, keystype key []) {// Binary Search int low = 1, high = L. recnum, mid; while (low <= high) {mid = (low + high)/2; If (equal (Key, L. R [Mid]. keys) return mid; else if (little (Key, L. R [Mid]. keys) High = mid-1; else low = Mid + 1;} return 0;} // search_bin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.