Current location - Plastic Surgery and Aesthetics Network - Clothing company - C language homework
C language homework
Connect to another account

list.h

#ifndef? List _h

# Definition? List _h

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

# include & ltstring.h & gt

# include & ltmath.h & gt

typedef? struct? nNode? Node;

struct? nNode

{

//? Upward pointer

Node *? nUp

//? Down pointer

Node *? nDown

//? Student number

int? iId

//? class

char*? pcClass

//? (full name)

char*? pcName

//? mathematics

Floating? fMath

//? English

Floating? Feng;

//? computer

Floating? fCmp

//? average score

Floating? fAver

};

typedef? Structure

{

Node *? nTop

Node *? nBottom

int? iSize

}? List;

//? New node

Node *? Node_new(int? iId,? char*? pcClass,? char*? pcName,? Floating? fMath,? Floating? acEng? Floating? acCmp);

//? Delete node

Invalid? Node_delete(Node*? nNode);

//? The value of the output node

Invalid? Node_print(Node*? nNode);

//? New link list

List *? list _ new(void);

//? Delete link list

Invalid? List_delete(List*? lList);

//? Add a node from the top of the linked list

Invalid? List_pushTop(List*? lList? Node *? nNewNode);

//? Take the node from the top of the linked list.

Node *? List_popTop(List*? lList);

//? Add a node from the bottom of the linked list

Invalid? List_pushBottom(List*? lList? Node *? nNewNode);

//? The node is taken out from the bottom of the linked list.

Node *? List_popBottom(List*? lList);

//? The node is inserted from the specified position in the linked list.

Invalid? List_insert(List*? lList? Node *? New node? int? iIndex);

//? Removes the specified node from the linked list.

Invalid? List_remove(List*? lList? Node *? nOldNode);

//? Traverse the linked list? Invalid? (* Access) (Node *)? Is a pointer to a function.

Invalid? List_traverse(List*? lList? Invalid? (* access) (node *);

//? Which node in the linked list is this node?

int? getIndex(List*? lList? Node *? nOldNode);

//? Sort by average score

Invalid? List_sortByAver(List*? lList);

//? Sort by computer score

Invalid? List_sortByCmp(List*? lList);

//? Output by student number

Invalid? List_printById(List*? lList);

//? Output by name

Invalid? List_printByName(List*? lList);

#endif? //? list_hlist.c

# contains "list.h"

//? New node

Node *? Node_new(int? iId,? char*? pcClass,? char*? pcName,? Floating? fMath,? Floating? Feng? Floating? fCmp)

{

int? iSize

Node *? nNode? =? (node *)malloc(sizeof (node));

//? Set the up pointer

nNode->; nUp? =? NULL

//? Set the pointer down

nNode->; nDown? =? NULL

//? Set student number

nNode->; iId? =? iId

//? Set up courses

if(pcClass? ! =? Empty)

iSize? =? strlen(PC class);

other

iSize? =? 0;

If (iSize? ! =? 0)

{

nNode->; pcClass? =? (char *)malloc(sizeof(char)*(iSize)? +? 1);

Strcpy(n node->; pcClass,? PC class);

nNode->; pcClass[iSize]? =? '\0';

}

//? Group name

if(pcName? ! =? Empty)

iSize? =? strlen(PC name);

other

iSize? =? 0;

If (iSize? ! =? 0)

{

nNode->; pcName? =? (char *)malloc(sizeof(char)*(iSize)? +? 1);

Strcpy(n node->; pcName,? PC name);

nNode->; pcName[iSize]? =? '\0';

}

//? Set math scores

nNode->; fMath? =? fMath

//? Set English scores

nNode->; Feng? =? Feng;

//? Set computer scores

nNode->; fCmp? =? fCmp

//? Set average score

nNode->; fAver? =? (fMath? +? Feng? +? fCmp)/3.0;

Return? nNode

}

//? Delete node

Invalid? Node_delete(Node*? nNode)

{

Free (nNode-& gt;; PC class);

Free (nNode-& gt;; PC name);

Free (n node);

}

//? The value of the output node

Invalid? Node_print(Node*? nNode)

{

//? Output student number

Printf ("student ID: %d\t",? nNode->; iId);

//? Output type

Printf ("Class: %s\t ",? nNode->; PC class);

//? Output name

Printf ("Name: %s\t ",? nNode->; PC name);

//? Output math scores

Printf ("Math: %. 1f\t ",nNode->; fMath);

//? Output English scores

Printf ("English: %. 1f\t", nnode->; Feng);

//? Output computer score

Printf ("computer: %. 1f\t", nnode->; fCmp);

//? Output average score

Printf ("average score: %.2f\n", nnode->; fAver);

}

//? New link list

List *? List_new(void)

{

List *? Lister. =? (List *)malloc(sizeof(List));

lList-& gt; iSize? =? 0;

lList-& gt; nTop? =? Node_new(0,? "",? "",? 0.0,? 0.0,? 0.0);

lList-& gt; nBottom? =? Node_new(0,? "",? "",? 0.0,? 0.0,? 0.0);

lList-& gt; nTop->; nDown? =? lList-& gt; nBottom

lList-& gt; nBottom-& gt; nUp? =? lList-& gt; nTop

Return? lList

}

//? Delete link list

Invalid? List_delete(List*? lList)

{

Node *? nNode

for(; ? lList-& gt; iSize & gt0; ? )

{

nNode? =? lList-& gt; nTop->; nDown

lList-& gt; nTop->; nDown? =? lList-& gt; nTop->; n down-& gt; nDown

node _ delete(n node);

lList-& gt; iSize? - ;

}

if(lList-& gt; nTop? ! =? Empty)

node _ delete(lList-& gt; nTop);

if(lList-& gt; nBottom? ! =? Empty)

node _ delete(lList-& gt; nBottom);

Free (llist);

}

//? Add a node from the top of the linked list

Invalid? List_pushTop(List*? lList? Node *? New node)

{

//? New node? nUp? The pointer is connected to the top node of the linked list.

nnew node-& gt; nUp? =? lList-& gt; nTop

//? New node? nDown? The pointer is connected to the next node at the top of the linked list.

nnew node-& gt; nDown? =? lList-& gt; nTop->; nDown

//? The next node of the top node of the linked list? nUp? The pointer is connected to the new node

lList-& gt; nTop->; n down-& gt; nUp? =? nNewNode

//? Top node of linked list? nDown? The pointer is connected to the new node

lList-& gt; nTop->; nDown? =? nNewNode

lList-& gt; iSize? ++;

}

//? Take the node from the top of the linked list.

Node *? List_popTop(List*? lList)

{

//? Backup the node that will pop up.

Node *? nNode? =? lList-& gt; nTop->; nDown

if(lList-& gt; iSize? & gt? 0)

{

//? The node under the top node of the linked list? nUp? The pointer is connected to the top node of the linked list.

lList-& gt; nTop->; n down-& gt; n down-& gt; nUp? =? lList-& gt; nTop

//? Top node of linked list? nDown? The pointer is connected to the lower node.

lList-& gt; nTop->; nDown=? lList-& gt; nTop->; n down-& gt; nDown

nNode->; nUp? =? NULL

nNode->; nDown? =? NULL

lList-& gt; iSize? - ;

}

other

printf("%s\n "," List_popTop()? Function error, this linked list is empty, and there are no nodes to fetch. ”);

Return? nNode

}

//? Add a node from the bottom of the linked list

Invalid? List_pushBottom(List*? lList? Node *? New node)

{

//? New node? nDown? The pointer is connected to the bottom node of the linked list.

nnew node-& gt; nDown? =? lList-& gt; nBottom

//? New node? nUp? The pointer is connected to the previous node at the bottom of the linked list.

nnew node-& gt; nUp? =? lList-& gt; nBottom-& gt; nUp

//? The previous node of the bottom node of the linked list? nDown? The pointer is connected to the new node

lList-& gt; nBottom-& gt; nUp-& gt; nDown? =? nNewNode

//? The bottom node of the linked list? nUp? The pointer is connected to the new node

lList-& gt; nBottom-& gt; nUp? =? nNewNode

lList-& gt; iSize? ++;

}

//? The node is taken out from the bottom of the linked list.

Node *? List_popBottom(List*? lList)

{

//? Backup the node that will pop up.

Node *? nNode? =? lList-& gt; nBottom-& gt; nUp

if(lList-& gt; iSize? & gt? 0)

{

//? The upper node on the bottom node of the linked list? nDown? The pointer is connected to the bottom node of the linked list.

lList-& gt; nBottom-& gt; nUp-& gt; nUp-& gt; nDown? =? lList-& gt; nBottom

//? Of the bottom node of the linked list? nUp? The pointer is connected to the upper node.

lList-& gt; nBottom-& gt; nUp? =? lList-& gt; nBottom-& gt; nUp-& gt; nUp

nNode->; nUp? =? NULL

nNode->; nDown? =? NULL

lList-& gt; iSize? - ;

}

other

printf("%s\n "," List_popBottom()? Function error, this linked list is empty, and there are no nodes to fetch. ”);

Return? nNode

}

//? The node is inserted from the specified position in the linked list.

Invalid? List_insert(List*? lList? Node *? New node? int? Index)

{

Node *? Nord? =? lList-& gt; nTop->; nDown

int? Me;

for(I = 0; ? Me & ltiIndex? i++)

Nord? =? Nord? -& gt; nDown

//? Release? New node? Node insertion? Nord? Above the node

nnew node-& gt; nUp? =? nold node-& gt; nUp

nnew node-& gt; nDown? =? nOldNode

nold node-& gt; nUp-& gt; nDown? =? nNewNode

nold node-& gt; nUp? =? nNewNode

lList-& gt; iSize? ++;

}

//? Removes the specified node from the linked list.

Invalid? List_remove(List*? lList? Node *? nOldNode)

{

//? Disconnect? The front and back links of the nOldNode node

nold node-& gt; nUp-& gt; nDown? =? nold node-& gt; nDown

nold node-& gt; n down-& gt; nUp? =? nold node-& gt; nUp

lList-& gt; iSize? - ;

}

//? Traverse the linked list? Invalid? (* Access) (Node *)? Is a pointer to a function.

Invalid? List_traverse(List*? lList? Invalid? (* Access) (Node *))

{

//? Get the top node pointer

Node *? nNode? =? lList-& gt; nTop

int? Me? iSize? =? lList-& gt; iSize

for(I = 0; ? Me & ltiSize? i++)

{

nNode? =? nNode->; nDown

Visit (n node);

}

}

//? Which node in the linked list is this node?

int? getIndex(List*? lList? Node *? nOldNode)

{

int? Me? iSize? =? lList-& gt; iSize

Node *? nNode? =? lList-& gt; nTop

for(I = 0; ? Me & ltiSize? ; ? i++)

{

nNode? =? nNode->; nDown

if(nOldNode? ==? nNode)

Return? Me;

}

Return? - 1;

}

//? Sort by average score

Invalid? List_sortByAver(List*? lList)

{

Node *? nNode? =? NULL

Node *? nMaxNode? =? NULL

int? Me? j,? iSize? =? lList-& gt; iSize

Floating? fMax

for(I = 0; ? Me & ltiSize? i++)

{

fMax? =? 0.0;

nNode? =? lList-& gt; nTop

for(j = iSize-I; ? j & gt0; ? j -)

{

nNode? =? nNode->; nDown

if(n node-& gt; fAver? & gt? fMax)

{

fMax? =? nNode->; fAver

nMaxNode? =? nNode

}

}

//? Remove the node with the highest average score.

List_remove(lList,nmax node);

//? Add the highest average segment from the bottom of the linked list.

List_pushBottom(lList,nmax node);

}

}

//? Sort by computer score

Invalid? List_sortByCmp(List*? lList)

{

Node *? nNode? =? NULL

Node *? nMaxNode? =? NULL

int? Me? j,? iSize? =? lList-& gt; iSize

Floating? fMax

for(I = 0; ? Me & ltiSize? i++)

{

fMax? =? 0.0;

nNode? =? lList-& gt; nTop

for(j = iSize-I; ? j & gt0; ? j -)

{

nNode? =? nNode->; nDown

if(n node-& gt; fCmp? & gt? fMax)

{

fMax? =? nNode->; fCmp

nMaxNode? =? nNode

}

}

//? Remove the tallest computer node.

List_remove(lList,nmax node);

//? Add the highest computer part from the bottom of the linked list.

List_pushBottom(lList,nmax node);

}

}

//? Output by student number

Invalid? List_printById(List*? lList)

{

int? iId

id:

Printf("%s\n ","Please enter your student number. If you want to quit, please enter? 0:");

scanf("%d ",& ampiId);

//? If the input is yes? 0? Exit cycle

If (iId? ==? 0)

Return;

//? Get the top node pointer

Node *? nNode? =? lList-& gt; nTop

int? Me? iSize? =? lList-& gt; iSize

for(I = 0; ? Me & ltiSize? i++)

{

nNode? =? nNode->; nDown

if(n node-& gt; iId? ==? iId)

{

//? Output student number

Printf ("student ID: %d\t",? nNode->; iId);

//? Output type

Printf ("Class: %s\t ",? nNode->; PC class);

//? Output name

Printf ("Name: %s\t ",? nNode->; PC name);

//? Output math scores

Printf ("Math: %. 1f\t ",nNode->; fMath);

//? Output English scores

Printf ("English: %. 1f\t", nnode->; Feng);

//? Output computer score

Printf ("computer: %. 1f\t", nnode->; fCmp);

//? Output average score

Printf ("average score: %.2f\n", nnode->; fAver);

Return;

}

}

Printf("%s\n ","There is no record of this student, please re-enter: ");

goto? id;

}

//? Output by name

Invalid? List_printByName(List*? lList)

{

Charles? AC name[32];

Name:

Printf("%s\n ","Please enter your name. If you want to quit, please enter? NULL:“);

scanf("%s ",& ampAC name[0]);

//? If the input is yes? NULL? Exit cycle

if((acName[0]? ==? n’)? & amp& amp? (acName[ 1]? ==? u’)? & amp& amp? (acName[2]? ==? l’)? & amp& amp? (acName[3]? ==? l '))

Return;

//? Get the top node pointer

Node *? nNode? =? lList-& gt; nTop

int? Me? iSize? =? lList-& gt; iSize

for(I = 0; ? Me & ltiSize? i++)

{

nNode? =? nNode->; nDown

if(strCmp(n node-& gt; pcName,? acName))

{

//? Output student number

Printf ("student ID: %d\t",? nNode->; iId);

//? Output type

Printf ("Class: %s\t ",? nNode->; PC class);

//? Output name

Printf ("Name: %s\t ",? nNode->; PC name);

//? Output math scores

Printf ("Math: %. 1f\t ",nNode->; fMath);

//? Output English scores

Printf ("English: %. 1f\t", nnode->; Feng);

//? Output computer score

Printf ("computer: %. 1f\t", nnode->; fCmp);

//? Output average score

Printf ("average score: %.2f\n", nnode->; fAver);

Return;

}

}

Printf("%s\n ","There is no record of this student, please re-enter: ");

goto? Name;

}main.c

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

# include & ltstring.h & gt

# include & ltmath.h & gt

# contains "list.h"

# contains "oper.h"

int? Major (invalid)

{

//? Create a linked list

List *? Lister. =? list _ new();

int? iMenu? =? 0;

Main menu:

iMenu? =? Menu ("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

1- Add a record? 2- Query records? 3- Sort records? 4- Delete record \n\

5- Modify the record? 6- Analysis records? 7- output record? 8- Log out of the system \n\

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n \

Please enter the number corresponding to the option: \ n ");

Switch? (iMenu)

{

Case? 1:

//? append record

addRec(lList);

goto? Main menu;

Case? 2:

//? Query record

src rec(lList);

goto? Main menu;

Case? 3:

//? Classified record

sortRec(lList);

goto? Main menu;

Case? 4:

//? deletion record

Del Rick (llist);

goto? Main menu;

Case? 5:

//? amendment record

modRec(lList);

goto? Main menu;

Case? 6:

//? Analysis records? 60.0? This is the passing line.

analRec(lList,60.0);

goto? Main menu;

Case? 7:

//? Output record

oputRec(lList);

goto? Main menu;

Case? 8:

//? take sth down

Break;

Default value:

Printf("%s\n ",the option you entered does not exist, please re-enter);

goto? Main menu;

}

//? Delete link list

list _ delete(lList);

Return? 0;

} End of code.