# include
#include
#include
#include
using namespace std;
# define OK 1
# define the ERROR 0
# define OVERFLOW - 2
Typedef int the Status;//the Status is the function return value type, its value is the function result Status code,
Typedef int ElemType;//ElemType to define data types, this is set to int
Struct Book {
String id;//ISBN
string name;//title
Double price.//pricing
};
Typedef struct LNode {
The Book data.//node data fields
Struct LNode * next;//node pointer domain
} LNode * LinkList;//LinkList for pointer to structure LNode type
String head_1, head_2 head_3;
Int length;
The Status InitList_L (LinkList & amp; 2.6 L) {//algorithm singly linked lists of initialization
//constructs an empty singly linked lists L
L=new LNode;//generated new node as the head node, with the head pointer pointing to L head node
L - & gt; Next=NULL;//head node pointer field empty
Return OK;
}
The Status GetElem_L (LinkList L, int I, Book & amp; E) {//algorithm 2.7 singly linked lists of values
//in the lead the singly linked list of nodes L find the ith element
With e//returns the value of the ith a data element in L
int j;
LinkList p;
P=L - & gt; Next;
J=1;//initialization, pointing to the first node p, j for the counter
While (j & lt; I & amp; & P) {//arranges backward scan chain domain until p points to the ith element or p is empty
P=p - & gt; Next;//p points to the next node
+ + j;//counter j + 1
}
if (! P | | j & gt; I)
Return the ERROR;//I value is not legal I> n or i<=0
E=p - & gt; data;//take the case of a node data fields I
Return OK;
}//GetElem_L
LNode * LocateElem_L (LinkList L, int e) {//algorithm according to the value of 2.8 find
//in the lead the singly linked list of nodes L find the value of e element
LinkList p;
P=L - & gt; Next;
While (p & amp; & P - & gt; Data. The price!=e)//suitable chain domain scanning back, until the p is empty or referred to in p nodes data domain equal to e
P=p - & gt; Next;//p points to the next node
Return the p;//find success node address of the value of e p, lookup failure p is NULL
}//LocateElem_L
The Status ListInsert_L (LinkList & amp; Int L, I, Book & amp; E) {//algorithm 2.9 singly linked lists of insert
//in the lead the singly linked list of nodes L the position I insert values for e new node
int j;
LinkList p, s;
P=L;
J=0;
While (p & amp; & J & lt; I - 1) {
P=p - & gt; Next;
+ + j;
}//find the I? A node, p points to the node
if (! P | | j & gt; I - 1)
Return the ERROR;//I> I S=new LNode;//generated new node * s
S - & gt; Data=https://bbs.csdn.net/topics/e;//the node * s data fields set to e
S - & gt; Next=p - & gt; Next;//will nodes * s domain to the ai
P - & gt; Next=s;//the node * p * s domain to the nodes
+ + length;
Return OK;
}//ListInsert_L
The Status ListDelete_L (LinkList & amp; 2.9 L, int I) {//algorithm singly linked list of deleted
//in the lead the singly linked list of nodes L, delete the position I
LinkList p, q;
int j;
P=L;
J=0;
While ((p - & gt; Next) & amp; & (j & lt; I - 1))//find the I? A node, p points to the node
{
P=p - & gt; Next;
+ + j;
}
if (! (p - & gt; Next) | | (j & gt; I - 1))
Return the ERROR;//when i> N or i<1, remove position is unreasonable
Q=p - & gt; Next;//temporary preservation is delete node address for released
P - & gt; Next=q - & gt; Next;/change/delete nodes precursors of pointer field
The delete q;//release delete node space
- length;
Return OK;
}//ListDelete_L
Void CreateList_H (LinkList & amp; L, int n) {//algorithm 2.11 forward method to create a singly linked list
//inverse order input values of n elements, to establish an end singly linked list of nodes L
LinkList p;
L=new LNode;
L - & gt; Next=NULL;//to build a lead the first node of empty list
Length=0;
Fstream file;
File. The open (" book. TXT ");
if (! The file) {
Cout & lt; <"Not find relevant file to open!" The exit (ERROR);
}
The file & gt;> Head_1 & gt;> Head_2 & gt;> Head_3;
while (! File. The eof ()) {
P=new LNode;//generate new node * p
The file & gt;> P - & gt; Data. The id & gt;> P - & gt; Data. The name & gt;> P - & gt; Data. The price;//input element value is assigned to the new node * p data domain
P - & gt; Next=L - & gt; Next;
L - & gt; Next=p;//insert the new node * p after the end node
Length++;//statistics for the chain length of the table
}
file.close();
}//CreateList_F
Void CreateList_R (LinkList & amp; L, int n) {//algorithm 2.12 after interpolation to create singly linked list
//input is a sequence of n elements values, establish a singly linked list of nodes with header L
LinkList p, r;
L=new LNode;
L - & gt; Next=NULL;//to build a lead the first node of empty list
R=L;//the tail pointer r to head node
Length=0;
Fstream file;//open the file to read and write operations
File. The open (" book. TXT ");
if (! The file) {
Cout & lt; <"Not find relevant file to open!" The exit (ERROR);
}
The file & gt;> Head_1 & gt;> Head_2 & gt;> Head_3;
while (! File. The eof ()) {//use the information in the file after interpolation is inserted into the list
P=new LNode;//generated new node
The file & gt;> P - & gt; Data. The id & gt;> P - & gt; Data. The name & gt;> P - & gt; Data. The price;//input element value is assigned to the new node * p data domain
P - & gt; Next=NULL;
R - & gt; Next=p;//insert the new node * p * r end nodes after
R=p;//r point to the new end node * p
Length++;//statistics for the chain length of the table
}
file.close();
}//CreateList_L
Int main () {
Int a, n, choose;
Double price.
The Book e;
LinkList L, p;
Cout & lt; <"1. Establish \ n";
Cout & lt; <"2. Input \ n";
Cout & lt; <"3. \ n values";
Cout & lt; <"4. Find \ n";
Cout & lt; <"5. Insert the \ n";
Cout & lt; <"6. Delete the \ n";
Cout & lt; <"7. Output \ n";
Cout & lt; <"0. Quit \ n \ n";
Choose=1;
While (choose!=0) {
Cout & lt; <"Please select:";
Cin & gt;> Choose;
The switch (choose) {
Case 1://build a singly linked list
If (InitList_L (L))
Cout & lt; <"Successful build list! \ n \ n ";
break;
Case 2://after using interpolation method to create a single table
CreateList_R (L, length);
Cout & lt; <"At the end of input book. TXT message \ n \ n";
break;
Case 3://singly linked lists according to the sequence number value
Cout & lt; <"Please enter a location for values:";
Cin & gt;> a;
If (GetElem_L (L, a, e) {
Cout & lt; <"Find success \ n";
Cout & lt; <"The first" & lt; Cout & lt;