Difference between r1.2 and the current
@@ -97,7 +97,97 @@
}}}
== 이원준 ==
----
== 이원준 ==
print랑 pop은 없슴다.
{{{
#include<stdio.h>
#include<string.h>
typedef struct _norm{
char *name;
struct _norm *next;
}norm;
typedef struct _grade{
char grade[3];
struct norm *head;
}grade;
void push(grade *head, char key[3], char *name){
char *temp = (char *)malloc(sizeof(name) * strlen(name));
norm* dir;
int num;
int i;
for (i = 0; i < 8; i++){
if (strcmp(head[i].grade, key) == 0){
num = i;
break;
}
}
dir = head[i].head;
strcpy(temp, name);
norm *ntemp = (norm *)malloc(sizeof(norm));
ntemp->name = temp;
ntemp->next = NULL;
if (dir == NULL){
head[i].head = ntemp;
return;
}
while (dir->next != NULL){
dir = dir->next;
}
dir->next = ntemp;
}
void print_all(grade *head){
int i;
for (i = 0; i < 8; i++){
if (head[i].head == NULL){
printf("없어요.\n");
continue;
}
}
}
void main(){
grade head[8];
norm* temp;
int i, j;
for (i = 0; i < 8; i++){
head[i].head = NULL;
head[i].grade[0] = 'A' + (i/2);
head[i].grade[2] = '\0';
if (i % 2 == 0)
head[i].grade[1] = '0';
else
head[i].grade[1] = '+';
}
head->head = NULL;
push(head, "A+", "lee");
push(head, "A+", "kim");
temp = head[1].head;
printf("%s", temp->name);
printf("%s", temp->next->name);
}
}}}
== 남헌 ==----
5.2. 박인서 ¶
- bucket sort
#include <stdio.h> #include <string.h> #include <stdlib.h> #define LEN 5 typedef struct data{ char * student; struct data * next; }stu; void push(stu * data,char * val) { stu * temp=(stu *)malloc(sizeof(stu)); temp->student=val,temp->next=NULL; while(data->next!=NULL) data=data->next; data->next=temp; } void print(stu * data) { if(data->next==NULL) return; printf("%s : ",data->student); while(data->next->next!=NULL) { data=data->next; printf("%s, ",data->student); } printf("%s\n",data->next->student); } int main() { stu data[8]; char * key=(char *)malloc(sizeof(char)*3); char * value[LEN]; int i; data[0].student="A+",data[1].student="A0"; data[2].student="B+",data[3].student="B0"; data[4].student="C+",data[5].student="C0"; data[6].student="D+",data[7].student="D0"; for(i=0;i<8;i++) data[i].next=NULL; for(i=0;i<LEN;i++) value[i]=(char *)malloc(sizeof(char)*100); for(i=0;i<LEN;i++) { printf("insert %d key\n",i+1); scanf("%s",key); printf("insert %d value\n",i+1); scanf("%s",value[i]); if(!strcmp(key,"A+")) push(&data[0],value[i]); if(!strcmp(key,"A0")) push(&data[1],value[i]); if(!strcmp(key,"B+")) push(&data[2],value[i]); if(!strcmp(key,"B0")) push(&data[3],value[i]); if(!strcmp(key,"C+")) push(&data[4],value[i]); if(!strcmp(key,"C0")) push(&data[5],value[i]); if(!strcmp(key,"D+")) push(&data[6],value[i]); if(!strcmp(key,"D0")) push(&data[7],value[i]); } for(i=0;i<8;i++) print(&data[i]); return 0; }
5.3. 이원준 ¶
print랑 pop은 없슴다.
#include<stdio.h> #include<string.h> typedef struct _norm{ char *name; struct _norm *next; }norm; typedef struct _grade{ char grade[3]; struct norm *head; }grade; void push(grade *head, char key[3], char *name){ char *temp = (char *)malloc(sizeof(name) * strlen(name)); norm* dir; int num; int i; for (i = 0; i < 8; i++){ if (strcmp(head[i].grade, key) == 0){ num = i; break; } } dir = head[i].head; strcpy(temp, name); norm *ntemp = (norm *)malloc(sizeof(norm)); ntemp->name = temp; ntemp->next = NULL; if (dir == NULL){ head[i].head = ntemp; return; } while (dir->next != NULL){ dir = dir->next; } dir->next = ntemp; } void print_all(grade *head){ int i; for (i = 0; i < 8; i++){ if (head[i].head == NULL){ printf("없어요.\n"); continue; } } } void main(){ grade head[8]; norm* temp; int i, j; for (i = 0; i < 8; i++){ head[i].head = NULL; head[i].grade[0] = 'A' + (i/2); head[i].grade[2] = '\0'; if (i % 2 == 0) head[i].grade[1] = '0'; else head[i].grade[1] = '+'; } head->head = NULL; push(head, "A+", "lee"); push(head, "A+", "kim"); temp = head[1].head; printf("%s", temp->name); printf("%s", temp->next->name); }