Home > Back-end >  Help me to analyse c singly linked lists the library system
Help me to analyse c singly linked lists the library system

Time:09-25

# include
# include
# include
using namespace std;
# define MAXSIZE 50
Struct the book
{
Char num.
Char name;
Float price;
};
Struct LNode
{
The book data [MAXSIZE];
Struct LNode * next;
} LNode * Linklist;
Void menu ()
{
Cout<" * * * * * * * * * * * * reply to the serial number corresponding operation on * * * * * * * * * * * * "& lt; Cout<" 1. Set up online library 4. X "insert in the first place I online library books & lt; Cout<" 2. Through online library 5. Delete the online library of the book "I & lt; Cout<" 3. To find the book 6 x. End "& lt; Cout<" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "& lt; }
Void mycreate (Linklist & amp; L)//when using forward method to create a singly linked list
{
Int I=1
While (I)
{
P=new LNode;
Cin> P - & gt; Data [I] num> P - & gt; Data [I] name> P - & gt; Data [I]. Price;
If (STRCMP (p - & gt; Data [I] num, "0") | | STRCMP (p - & gt; Data [I]. The name, "0") | | (L - & gt; Data [I]. Price! I++=0));
else break;
P - & gt; Next=L - & gt; Next;
L - & gt; Next=p;
}
}
Void myshow Linklist (L)
{
Int I=1;
LNode * p;
P=L - & gt; Next;
While (p)
{
Cout

Couti++;
P=p - & gt; Next;
}
}
Int myinsert (Linklist & amp; L, I, book x)
{
LNode * p;
P=L; Int j=1;
While (p& & j{
P=p - & gt; Next; J++;
}
if(! P | | j> I) the return 0;
S=new LNode;
S - & gt; Data. The num=x.n um. S - & gt; Data. The name=x.n ame; S - & gt; Data. Price=x.p rice;
S - & gt; Next=p - & gt; Next;
P - & gt; Next=s;
return 1;
}
Void mydelete (Linklist & amp; L, I)
{
LNode * p * q;
P=L; Int j=1;
While ((p - & gt; Next) & amp; & j{
P=p - & gt; Next; J++;
}
if(! (p - & gt; Next) | | j> I) the return 0;
Q=p - & gt; Next;
P - & gt; Next=q - & gt; Next;
The delete q;
return 1;
}
Int main ()
{
The book x;
Int I, n, m=1;
While (m)
{
The menu ();
Cin> n;
The switch (n)
{
Case 1: {
Mycreate (L);
break;
}
Case 2: myshow (& amp; L); break;
Case 3: {
Cout<" Input to the position of the insert I and book x each information: "& lt; Cin> i> X.n um> X.n ame> X.p rice;
Myinsert (L, I, x);
break;
}
Case 5: {
Cout<" Input to delete books position I: ";
Cin> i;
Mydelete (L, I);
break;
}
Case 6: m=0; break;
Default: cout<" * * * * * * * * * * * * * * * please re-enter the serial number * * * * * * * * * * * * * * * "& lt; }
}
return 0;
}

CodePudding user response:

?? Don't understand what you mean
  • Related