Created
March 23, 2019 08:59
-
-
Save maehrm/803c57856f9d15208dcf7c1cff003c39 to your computer and use it in GitHub Desktop.
平成20年度春期試験_基本情報午後問4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
typedef struct { | |
int next; | |
char value[4]; | |
} LIST; | |
LIST list[100]; | |
int listsize = 0, first = -1; | |
void makeList(const char []); | |
int organizingSearch(const char []); | |
void printList(void); | |
void makeList(const char mvalue[]) { | |
if (listsize != 0) { | |
list[listsize - 1].next = listsize; | |
} | |
else { | |
first = 0; | |
} | |
strcpy(list[listsize].value, mvalue); | |
list[listsize++].next = -1; | |
} | |
int organizingSearch(const char svalue[]) { | |
int current; | |
int temp; | |
current = first; | |
while (current != -1) { | |
if (strcmp(list[current].value, svalue) == 0) { | |
if (current != first) { | |
list[temp].next = list[current].next; | |
list[current].next = first; | |
first = current; | |
} | |
break; | |
} | |
else { | |
temp = current; /* α */ | |
current = list[current].next; | |
} | |
} | |
return current; | |
} | |
void printList(void) { | |
int current; | |
current = first; | |
while (current != -1) { | |
printf("%s", list[current].value); | |
current = list[current].next; | |
if (current != -1) printf(" -> "); | |
} | |
printf("\n"); | |
} | |
int main(void) { | |
char *str[] = {"usb", "cgi", "cpu", "dos", "fat"}; | |
int i, size = sizeof(str) / sizeof(str[0]); | |
for (i = 0; i < size; i++) { | |
makeList(str[i]); | |
} | |
printList(); | |
printf("%d\n", organizingSearch("cgi")); | |
printList(); | |
printf("%d\n", organizingSearch("cpu")); | |
printList(); | |
printf("%d\n", organizingSearch("dos")); | |
printList(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
平成20年度春季基本情報午後問4 - Mae向きなブログ