Array Storage Structure and Its Operation Algorithm Implementation-Bank Interest Rate Table Management

Source: Internet
Author: User

[Cpp] // file: "array_list.h" # ifndef _ ARRAYLIST_H_INCLUDE _ # define _ ARRAYLIST_H_INCLUDE _ # include <cstdio> # define maxlen 1000 template <typename Type> class List {public: list (): list_last (0) {}// constructor, the starting length of the linear table is 0 void Insert (int p, Type x) {if (list_last> = maxlen-1) printf ("list is full! \ N "); else if (p> list_last + 1) | (p <1) {printf (" position is not exist! \ N ") ;}else {for (int I = list_last; I >= p; I --) {element [I + 1] = element [I];} element [p] = x; list_last ++ ;}} void Delete (int p) {if (p> list_last) | (p <1 )) printf ("position is not exist! \ N "); else {list_last --; for (int I = p; I <= list_last; I ++) element [I] = element [I + 1];} int Locate (Type x) {for (int I = 1; I <= list_last; I ++) if (element [I] = x) return I; return (list_last + 1);} Type Retrieve (int p) {if (p> list_last) printf ("position is not exist! \ N "); else return element [p];} Type Previous (int p) {if (p <= 1) | (p> list_last )) printf ("Previous element is not exist! \ N "); else return element [P-1];} Type Next (int p) {if (p <1) | (p> = list_last )) printf ("Next element is not exist! \ N "); else return element [p + 1];} int End () {return (list_last + 1);} private: int list_last; type element [maxlen] ;};# endif [cpp] # include <iostream >#include <cstring> # include "array_list.h" using namespace std; struct rate {char name [30]; // bank name double current_rate; // current interest rate}; int main () {freopen ("in.txt", "r", stdin ); list <rate> R; struct rate x; char na [30]; int N; printf ("1 -- insert \ n2 -- delete \ n3 -- QUERY \ n4 -- Print \ n0 -- exit \ n"); while (cin> N) {switch (N) {case 1: int m; cin> m; // Number of inserts for (int I = 1; I <= m; I ++) {cin> x. name> x. current_rate; R. insert (I, x);} // Insert break after Insert; case 2: cin> x. name; for (int I = 1; I <= R. end ()-1; I ++) if (strcmp (R. retrieve (I ). name, x. name) = 0) R. delete (I); break; case 3: cin> x. name; for (int I = 1; I <R. end (); I ++) {www.2cto.com if (strcmp (R. retrieve (I ). name, x. name) = 0) cout <R. retrieve (I ). current_rate <endl;} break; case 4: for (int I = 1; I <R. end (); I ++) cout <R. retrieve (I ). name <"---" <R. retrieve (I ). current_rate <endl; break; case 0: return 0 ;} printf ("1 -- insert \ n2 -- delete \ n3 -- QUERY \ n4 -- Print \ n0 -- exit \ n");} return 0 ;}

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.