List, similar to the school information management system

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node {// student information data type
char name [20 is];
char Sex [15];
int Score;
struct Node * pNext;
} the Node, * • pNode;
void printList (• pNode PHEAD);

print_info void ()
{
the printf ( "________________________________ \ n-");
the printf ( "| Name | Sex | Score | \ n-");
the printf ( "| __________ | __________ | __________ | \ n-");
}

void arr_Change(char a[],char b[])
{
char c[20];
strcpy(c,a);
strcpy(a,b);
strcpy(b,c);
return;
}

void num_Change(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
return;
}

 

void input_Node (pNode student) // list element input function
{
// Scanf ( "% S \ S n-% \% n-D", & Student-> name, & Student-> Sex, & Student-> Score); // list element the output function
printf ( "name:");
Scanf ( "% S", & Student-> name);
printf ( "gender:");
Scanf ( "% S", & Student-> sex);
printf ( "score:" );
Scanf ( "% D", & Student-> Score);
return;
}

void output_Node (pNode student) // list elements of the output function
{
the printf ( "|% -10S |% -10S | -10D% | \ n-", & Student-> name, & Student-> Sex, Student-> Score);
the printf ( "| __________ | __________ | __________ | \ n-");
return;
}

pNode head_Create_List (int num) // list is used in order to create the first interpolation method, a reverse printing p-> Next = head-> Next; head-> Next = P;
{
int I = 0;
• pNode head;
• pNode P;
head-> pNext = NULL;
the printf ( "% d students enter information: \ n-", NUM);
the while (I <NUM)
{
P = (• pNode) the malloc (the sizeof (the Node));
input_Node (P);
p-> pNext = head-> pNext;
head-> pNext = P;
I ++;
}
return head;
}

void printList(pNode pHead)//打印链表
{
int i;
//printf("\n");
pNode p=pHead->pNext;
while(p!=NULL)
{
output_Node(p);
p=p->pNext;
}
printf("\n");
return;
}

pNode tail_Create_List (int num) // End interpolation END-> Next = Node; End Node =
{
int I = 0;
• pNode head = NULL; // first node
pNode tail = NULL; // End node
pNode node = NULL ; // intermediate node
head = (• pNode) the malloc (the sizeof (the node));
tail = head;
the printf ( "% d students enter information \ n-", NUM);
the while (I <NUM)
{
node = ( • pNode) the malloc (the sizeof (the Node));
input_Node (Node);
tail-> pNext = Node;
tail = Node;
I ++;
}
tail-> pNext = NULL;
return head;
}

void insertList (pNode pHead, int loc ) // in the linked list
{
int I;
• pNode P;
P = PHEAD;
for (I = 0; I <-LOC. 1; I ++)
{
P = p-> pNext;
}
• pNode S;
printf ( "Please enter student information you want to insert: \ the n-");
S = (pNode) malloc (sizeof (the Node));
input_Node (S); // insert input information
s-> pNext = p-> pNext;
p-> pNext = S;
return;
}

void deleteList (pNode pHead, int loc ) // delete the list
{
int I;
• pNode P, q; // node P is the precursor, q is the deletion node
P = PHEAD;
for (I = 0; I <-LOC. 1; I ++ )
{
P = p-> pNext;
}
Q = p-> pNext;
p-> = Q- pNext> pNext;
Free (Q);
return;
}

int get_Single_Listlength(pNode pHead)
{
int length=0;
pNode p;
p=pHead;
while(p!=NULL)
{
p=p->pNext;
length++;
}
return length-1;
}

pNode bubble_Single_List(pNode pHead)
{
pNode pFirst,pEnd;
pFirst=NULL;pEnd=NULL;
pFirst=pHead;
while(pFirst!=pEnd)
{
while(pFirst->pNext!=pEnd)
{
if(pFirst->score<pFirst->pNext->score)
{
arr_Change(pFirst->name,pFirst->pNext->name);
arr_Change(pFirst->sex,pFirst->pNext->sex);
num_Change(&pFirst->score,&pFirst->pNext->score);
}
pFirst=pFirst->pNext;
}
pEnd=pFirst;
pFirst=pHead;
}
return pHead;
}


void destoryList (pNode pHead) // release the memory function
{
• pNode P;
P = PHEAD;
the while (! P = NULL)
{
Free (P);
P = p-> pNext;
}
return;
}


main int (void)
{
int NUM = 0;
• pNode head, Bubble;
int LOC = 0;
int length;
int deleteLoc;
int changeFlags;
the printf ( "Please enter student information by interpolation number of single end of the list: \ n" );
scanf ( "% d", & NUM);
printf ( "the number of students you want to insert is:% d \ the n-", NUM);
head = tail_Create_List (NUM);
printf ( "\ the n-current students the following information \ n-");
print_info ();
printList (head);

the printf (" operating in accordance Tip: \ n-");
the printf (" Please enter the operation symbols 1: insert, 2: delete, 3: exit \ the n-");
scanf ("% d ", & changeFlags);
the while (changeFlags = 3)!
{
int LOC, deleteloc;

IF (changeFlags == 1)
{
printf (" Please enter the location you want to insert: \ n " );
Scanf ( "% D", & LOC);
insertList(head,loc);
}
IF (changeFlags == 2)
{
printf ( "Please enter the location you want to delete: \ the n-");
scanf ( "% d", & deleteloc);
deleteList (head, deleteloc);
}

printf ( "Please continue the entry operation symbols, 1: insert, 2: delete, 3: exit, \ n-");
changeFlags = 0;
Scanf ("% D ", & changeFlags);
IF (changeFlags == 3)
{
BREAK;
}
}

// length = get_Single_Listlength (head);
Bubble = bubble_Single_List (head);
print_info ();
printList (Bubble);

destoryList (head); // list destruction
return 0;
}

 

// operating environment DEVC ++

Guess you like

Origin www.cnblogs.com/--dafeqi--dafenqi--dafenqi/p/11607490.html