I occasionally wrote a few programs about linked list set operations. Some people may say that they do not understand it very well. I hope I can explain it. Of course,
Even if the program is encapsulated by a layer, it may not be very natural to understand it. In addition, the program itself is partially incomplete and cannot be understood!
I roughly summarized the analysis of the main function. As for the main function, let's take a closer look at it ~~
1. Define a connector data structure type
Struct Node
{
DataType info;
PNode link;
};
2. Use a LinkType data structure to encapsulate the header and tail of the contact, that is, to save the pointer of the header and tail.
Struct LinkType
{
PNode base;
PNode top;
};
3. Define a point type pointer PNode and a link type pointer PLinkType
4. the PLinkType pointer is used when we access the linked list, stack, or queue, because it can make our hierarchy and thinking clearer (of course not so, ).
5. Define our functions
PLinkType CreatePointer (void): Creates a PLinkType contact to store the pointer of the header and tail, and initializes them, both set to NULL.
PLinkType CreateHeadNode (PLinkType pltype): create header and tail contacts of the PNode type and leave them empty.
PLinkType push_Type (PLinkType pltype, DataType n): used to set the length of the linked list or other data types we want, and reset our tail point.
PLinkType print_Type (PLinkType pltype): output the output of our linked list. At this time, the tail pointer is automatically subtracted. When the header and the end are equal, the output ends and a PLinkType pointer is returned.
PLinkType pop_Type (PLinkType pltype): This function is redundant and can be removed.
PLinkType de_Type (PLinkType pltype, DataType j): output j data of the linked list or queue from the front, and move the header pointer back.
PLinkType pop_Stack (PLinkType pltype, DataType j) outputs the j data of the stack from the back, and moves the pointer forward to PLinkType free_all (PLinkType pltype) to release all the contact space.
6. the main function is mainly called the switch function, a main switch, two switches in the middle of each case (the natural end is equivalent to the third case (0 )) I don't need to explain it in detail here. ^_^
7. I have found many shortcomings after I write it. I don't know if you have found it. Well, let me know when I have modified it ~