186 lines
4.6 KiB
C
186 lines
4.6 KiB
C
|
/* file name: dList.c */
|
|||
|
/* <20><><EFBFBD>V<EFBFBD>䵲<EFBFBD><E4B5B2><EFBFBD>C<EFBFBD><43><EFBFBD>[<5B>J<EFBFBD>P<EFBFBD>R<EFBFBD><52> */
|
|||
|
|
|||
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
#include <string.h>
|
|||
|
|
|||
|
void init_f(void); /* <20><><EFBFBD>l<EFBFBD>Ʀ<EFBFBD><C6A6>C<EFBFBD>A<EFBFBD>إߤ@<40>Ÿ`<60>I<EFBFBD><49> head */
|
|||
|
void insert_f(void); /* <20><><EFBFBD>J<EFBFBD><4A><EFBFBD><EFBFBD> */
|
|||
|
void sort_f(void); /* <20>ƧǨ<C6A7><C7A8><EFBFBD> */
|
|||
|
void delete_f(void); /* <20>R<EFBFBD><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void display_f(void); /* <20><><EFBFBD>X<EFBFBD><58><EFBFBD><EFBFBD> */
|
|||
|
void modify_f(void); /* <20>ק<EFBFBD><D7A7><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void flushBuffer(void);
|
|||
|
|
|||
|
struct Student {
|
|||
|
char name[20]; /* <20>m<EFBFBD>W */
|
|||
|
int score; /* <20><><EFBFBD><EFBFBD> */
|
|||
|
struct Student *llink; /* <20>`<60>I<EFBFBD><49><EFBFBD>쵲 */
|
|||
|
struct Student *rlink; /* <20>`<60>I<EFBFBD>k<EFBFBD>쵲 */
|
|||
|
};
|
|||
|
struct Student *ptr, *head, *tail, *current, *prev, *temp;
|
|||
|
|
|||
|
int main(void)
|
|||
|
{
|
|||
|
char option1;
|
|||
|
|
|||
|
init_f();
|
|||
|
while(1) {
|
|||
|
printf("\n<EFBFBD><EFBFBD><EFBFBD>V<EFBFBD>쵲<EFBFBD><EFBFBD><EFBFBD>C<EFBFBD><EFBFBD><EFBFBD>B<EFBFBD>@<40><><EFBFBD><EFBFBD>\n");
|
|||
|
printf("************\n");
|
|||
|
printf(" 1.insert\n");
|
|||
|
printf(" 2.delete\n");
|
|||
|
printf(" 3.display\n");
|
|||
|
printf(" 4.modify\n");
|
|||
|
printf(" 5.quit\n");
|
|||
|
printf("*************\n");
|
|||
|
printf("<EFBFBD>п<EFBFBD><EFBFBD>J<EFBFBD>ﶵ(1-5): ");
|
|||
|
option1 = getchar();
|
|||
|
flushBuffer();
|
|||
|
switch (option1) {
|
|||
|
case '1':
|
|||
|
insert_f();
|
|||
|
break;
|
|||
|
case '2':
|
|||
|
delete_f();
|
|||
|
break;
|
|||
|
case '3':
|
|||
|
display_f();
|
|||
|
break;
|
|||
|
case '4':
|
|||
|
modify_f();
|
|||
|
break;
|
|||
|
case '5':
|
|||
|
printf("\n<EFBFBD>{<7B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
exit(0);
|
|||
|
}
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
void init_f(void) /* <20>]<5D>@<40><> head<61>A<EFBFBD>N<EFBFBD><4E><EFBFBD>k<EFBFBD>쵲<EFBFBD>ҫ<EFBFBD><D2AB>V<EFBFBD><56><EFBFBD><EFBFBD> */
|
|||
|
{
|
|||
|
ptr = (struct Student *) malloc(sizeof(struct Student));
|
|||
|
strcpy(ptr->name, "0");
|
|||
|
ptr->llink = ptr;
|
|||
|
ptr->rlink = ptr;
|
|||
|
head = ptr;
|
|||
|
tail = ptr;
|
|||
|
}
|
|||
|
|
|||
|
void insert_f(void)
|
|||
|
{
|
|||
|
ptr = (struct Student *) malloc(sizeof(struct Student));
|
|||
|
printf("\n <20>m<EFBFBD>W: ");
|
|||
|
scanf("%s", ptr->name);
|
|||
|
printf(" <20><><EFBFBD>Z: ");
|
|||
|
scanf("%d", &ptr->score);
|
|||
|
flushBuffer();
|
|||
|
|
|||
|
/* <20>H<EFBFBD><48><EFBFBD>ư<EFBFBD><C6B0>C<EFBFBD>ƦC */
|
|||
|
prev = head;
|
|||
|
current = head->rlink;
|
|||
|
while (current != head && current->score > ptr->score) {
|
|||
|
prev = current;
|
|||
|
current = current->rlink;
|
|||
|
}
|
|||
|
ptr->rlink = current;
|
|||
|
ptr->llink = prev;
|
|||
|
prev->rlink = ptr;
|
|||
|
current->llink = ptr;
|
|||
|
}
|
|||
|
|
|||
|
void delete_f(void)
|
|||
|
{
|
|||
|
char del_name[20];
|
|||
|
printf("\n <20><><EFBFBD>R<EFBFBD><52><EFBFBD>m<EFBFBD>W: ");
|
|||
|
scanf("%s", del_name);
|
|||
|
flushBuffer();
|
|||
|
prev = head;
|
|||
|
current = head->rlink;
|
|||
|
while (current != head && strcmp(del_name, current->name) != 0) {
|
|||
|
prev = current;
|
|||
|
current = current->rlink;
|
|||
|
}
|
|||
|
if (current != head) {
|
|||
|
prev->rlink = current->rlink;
|
|||
|
current->rlink->llink = prev;
|
|||
|
printf(" %s <20>w<EFBFBD>Q<EFBFBD>R<EFBFBD><52>\n", del_name);
|
|||
|
free(current);
|
|||
|
}
|
|||
|
else /* <20>䤣<EFBFBD><E4A4A3><EFBFBD><EFBFBD><EFBFBD>ƫh<C6AB><68><EFBFBD>ܿ<EFBFBD><DCBF>~ */
|
|||
|
printf(" %s <20><><EFBFBD>b<EFBFBD><62><EFBFBD>C<EFBFBD><43>\n", del_name);
|
|||
|
}
|
|||
|
|
|||
|
void modify_f(void)
|
|||
|
{
|
|||
|
char n_temp[20];
|
|||
|
printf("\n <20><><EFBFBD>ק諸<D7A7>m<EFBFBD>W: ");
|
|||
|
scanf("%s", n_temp);
|
|||
|
prev = head;
|
|||
|
current = head->rlink;
|
|||
|
while (current != head && strcmp(n_temp, current->name)) {
|
|||
|
prev = current;
|
|||
|
current = current->rlink;
|
|||
|
}
|
|||
|
if (current == head) {
|
|||
|
printf(" %s <20>S<EFBFBD><53><EFBFBD>b<EFBFBD><62><EFBFBD>C<EFBFBD><43>\n", n_temp);
|
|||
|
}
|
|||
|
else {
|
|||
|
printf(" ******************\n");
|
|||
|
printf(" <20>m<EFBFBD>W : %s\n", current->name);
|
|||
|
printf(" <20><><EFBFBD><EFBFBD>: %d\n", current->score);
|
|||
|
printf(" ******************\n");
|
|||
|
printf(" <20>п<EFBFBD><D0BF>J<EFBFBD>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
|
|||
|
scanf("%d", ¤t->score);
|
|||
|
flushBuffer();
|
|||
|
printf(" %s <20>w<EFBFBD>Q<EFBFBD>ק<EFBFBD>\n", n_temp);
|
|||
|
//<2F>N<EFBFBD>ק諸<D7A7>`<60>I<EFBFBD>[<5B>J<EFBFBD><4A><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>m
|
|||
|
//<2F><><EFBFBD>N current <20><><EFBFBD>`<60>I<EFBFBD><49><EFBFBD>w<EFBFBD><77> temp<6D>A<EFBFBD>í<EFBFBD><C3AD>s<EFBFBD>վ㥪<D5BE>B<EFBFBD>k<EFBFBD>`<60>I
|
|||
|
temp = current;
|
|||
|
prev->rlink = current->rlink;
|
|||
|
current->rlink->llink = prev;
|
|||
|
//<2F>A<EFBFBD>N temp <20>`<60>I<EFBFBD>[<5B>J<EFBFBD><4A><EFBFBD><EFBFBD><EFBFBD>C<EFBFBD><43>
|
|||
|
/* <20>H<EFBFBD><48><EFBFBD>ư<EFBFBD><C6B0>C<EFBFBD>ƦC */
|
|||
|
prev = head;
|
|||
|
current = head->rlink;
|
|||
|
while (current != head && current->score > temp->score) {
|
|||
|
prev = current;
|
|||
|
current = current->rlink;
|
|||
|
}
|
|||
|
temp->rlink = current;
|
|||
|
temp->llink = prev;
|
|||
|
prev->rlink = temp;
|
|||
|
current->llink = temp;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void display_f(void)
|
|||
|
{
|
|||
|
int count = 0;
|
|||
|
if (head->rlink == head) {
|
|||
|
printf("\n <20><><EFBFBD>C<EFBFBD>L<EFBFBD><4C><EFBFBD><EFBFBD>\n");
|
|||
|
}
|
|||
|
else {
|
|||
|
printf("\n");
|
|||
|
printf(" NAME SCORE\n");
|
|||
|
printf(" ----------------------\n");
|
|||
|
current = head->rlink;
|
|||
|
while (current != head) {
|
|||
|
printf(" %-15s %3d\n", current->name, current->score);
|
|||
|
count++;
|
|||
|
current = current->rlink;
|
|||
|
}
|
|||
|
printf(" ----------------------\n");
|
|||
|
printf(" <20>`<60>@<40><> %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n", count);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void flushBuffer(void)
|
|||
|
{
|
|||
|
while(getchar() != '\n')
|
|||
|
continue;
|
|||
|
}
|
|||
|
|