[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 ;}