U E D R , A S I H C RSS

자료구족발보쌈/0722

탈주자로 인하여 잠수함이 못내려가요. 더 무거워져야 될텐데..


1. 참여자 명단


함장 장용운 11학번 도스마스
선원 천준현 15학번 행방불명
최지혁 출석
박인서 도스마스
이정재 고향
이원준 출석
조종현 장염
남헌 도스마스

2. 수업

2.1. 진행

1. 장소 : 6층 학회실
2. 시간 : 14시 ~ 17시

2.2. 내용

보충. 스택과 큐 연습
  • 은행 관리 프로그램
탈주자들 안오면 잘라버리자

3. 코드

3.1. 예제1

  • 큐를 이용하여 은행에 저장된 사람이름, 계좌번호, 잔액을 입력받은 순서대로 나오게 작성하시오.

3.2. 예제2

  • 스택을 이용하여 은행에 저장된 사람이름, 계좌번호, 잔액을 입력받은 순서의 반대로 나오게 작성하시오.

4. 숙제

1. 스택과 큐 복습하기



5. 숙제 제출

5.1. 천준현


5.2. 최지혁


5.3. 박인서

5.3.1. 예제1

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

typedef struct bank{
	int money;
	int num;
	char * name;
}bank;

typedef struct node{
	bank val;
	struct node* next;
}node;

void push(node *);
void pop(node *);

int main()
{
	node head;
	int i;
	head.next=NULL;
	for(i=0;i<10;i++) push(&head);
	for(i=0;i<10;i++) pop(&head);
	return 0;
}

void push(node * target)
{
	node * newnode=(node *)malloc(sizeof(node));
	node * temp=target->next;
	int tmoney,tnum;
	char * tname=(char *)malloc(sizeof(char)*100);
	scanf("%s %d %d",tname,&tnum,&tmoney);
	newnode->val.name=tname;
	newnode->val.num=tnum;
	newnode->val.money=tmoney;
	target->next=newnode;
	newnode->next=temp;
}

void pop(node * target)
{
	node * kill=(node *)malloc(sizeof(node));
	if(target==NULL) abort();
	if(target->next->next==NULL)
	{
		printf("%s %d %d\n",target->next->val.name,target->next->val.num,target->next->val.money);
		kill=target->next;
		target->next=NULL;
		free(kill);
	}
	else pop(target->next);
}

5.3.2. 예제2

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

typedef struct bank{
	int money;
	int num;
	char * name;
}bank;

typedef struct node{
	bank val;
	struct node* next;
}node;

void push(node *);
void pop(node *);

int main()
{
	node head;
	int i;
	head.next=NULL;
	for(i=0;i<10;i++) push(&head);
	for(i=0;i<10;i++) pop(&head);
	return 0;
}

void push(node * target)
{
	node * newnode=(node *)malloc(sizeof(node));
	node * temp=target->next;
	int tmoney,tnum;
	char * tname=(char *)malloc(sizeof(char)*100);
	scanf("%s %d %d",tname,&tnum,&tmoney);
	newnode->val.name=tname;
	newnode->val.num=tnum;
	newnode->val.money=tmoney;
	target->next=newnode;
	newnode->next=temp;
}

void pop(node * target)
{
	node * kill = target->next;
	printf("%s %d %d\n",target->next->val.name,target->next->val.num,target->next->val.money);
	if(target->next==NULL) abort();
	target->next=target->next->next;
	free(kill);
}

5.4. 이정재


5.5. 이원준


5.5.1. 큐로 짬

(free따윈없다!)
  • 그러다 정말로 자유가 없어짐 - 박인서

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


typedef struct node{
	char v;
	struct node* next;
}node;

typedef struct account{
	
	node namehd;

	node anumhd;

	struct account* next;

}account;



void push(node*, char*);
account* acpush(account* hd);
void freeAll(node*);


int l = 10; //고객수

void main(){
	
	account ac = { NULL };
	account* tmp = &ac;
	account* pt = (account*)malloc(sizeof(account));


	char a;

	pt = &ac;
	for (int i = 0; i < l; i++)
	{
		printf("이름입력하3\n");
		for (int j = 0; 1; j++){
			a = fgetc(stdin);
			if (a == '\n') break;
			push(&(pt->namehd), &a);
		}


		printf("번호입력하3\n");
		for (int j = 0; 1; j++){
			a = fgetc(stdin);
			if (a == '\n') break;
			push(&(pt->anumhd), &a);


		}
		printf("\n");
		pt = acpush(pt);
		pt->anumhd.next = NULL;
		pt->namehd.next = NULL;
		pt->next = NULL;
	}
	

	pt = &ac;
	
	printf("----출력----\n");
	for (int i = 0; i < l; i++){
		printf("이름\n");
		freeAll(&(pt->namehd));
		printf("\n");

		printf("계좌\n");	
		freeAll(&(pt->anumhd));
		printf("\n");
		printf("\n");
		pt = pt->next;
	}

}



void push(node* hd, char* val){
	node* tmp = (node*)malloc(sizeof(node));
	node* pt = (node*)malloc(sizeof(node));

	pt = hd;
	while (pt->next != NULL)
	{
		pt = pt->next;
	}
	tmp->next = NULL;
	tmp->v = *val;

	pt->next = tmp;
	pt = pt->next;
}

account* acpush(account* ac){
	
	account* tmp = (account*)malloc(sizeof(account));

	tmp->next = NULL;

	ac->next = tmp;
	return ac->next;
}


void freeAll(node* hd){
	node* ntp;
	node* tmp = hd;
	while (hd->next != NULL){
		ntp = hd->next;
		printf("%c", ntp->v);
		ntp = ntp->next;
		hd->next = ntp;
	}
	hd = tmp;
}

5.5.2. 스택으로 짠거

그런거 없음

5.6. 조종현


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:38
Processing time 0.0326 sec