top of page

소스 코드 제출

공개·회원 50명

250816

/*


#include <stdio.h>



char a[201] = {0};


int stack[201] = {0};


int t = -1;


int counter = 0;



void push(){




int p = a[6] - '0';


t++;


if(a[7] != 32){


for(int i = 7; a[i] != 32; i++){


int q = a[i] - '0';


p = 10 * p + q;


}


}




stack[t] = p;


counter++;


return;




}



void top(){




if(counter == 0){


printf("-1\n");


return;


}




printf("%d\n", stack[t]);


return;



}



void pop(){


if(t == -1){


return;


}


stack[t] = 0;


t--;


counter--;


return;




}



void size(){




printf("%d\n", counter);


return;



}



void empty(){




if(counter == 0){


printf("true\n");


return;


}




printf("false\n");


return;



}



int main(){


int N;


scanf("%d\n", &N);




for(int i = 0; i < N; i++){


gets(a);




if(a[0]=='p'){




if(a[1]=='u'){


push();


}




else pop();


}




else if(a[0]=='t') top();


else if(a[0]=='s') size();


else empty();


}




return 0;


}



*/


/*


#include <stdio.h>



int front = 0;


int rear = 0;



int stack[5] = {0};




void push(int p){



front++;



if(front > 5 && rear == 0){



printf("Stack is full (Front: 5, Rear: 0)\n\n");



front--;



return;



}




if(front > 5 && rear > 0){


front--;


for (int i = 0; i + rear < 5; i++){


stack[i] = stack[i + rear];


}


for (int i = rear + 1; i < 5; i++){


stack[i] = 0;


}




front -= rear;


rear = 0;


stack[front++] = p;


printf("Stack is revised (Front: %d, Rear: 0)\n\n", front);


return;


}




printf("Front: %d, Rear: %d\n\n", front, rear);


stack[front-1] = p;




return;



}




void pop(){



if(front == 0 && rear == 0){



printf("Stack is empty(Front: 0, Rear: 0)\n\n");



return;



}



stack[rear++] = 0;




if(front == rear){



printf("Stack is emptied(Front: %d -> 0, Rear: %d -> 0)\n\n", front, rear);


front = 0;


rear = 0;


return;



}




printf("Front: %d, Rear: %d\n\n", front, rear);


return;



}




void view(){




for(int i=4;i>-1;i--){



printf("%d 번째 칸: %d\n", i, stack[i]);



}


printf("Front: %d, Rear: %d\n\n", front, rear);


return;



}




int main(){



int type;



int push_input;



printf("type 1: push()\ntype 2: pop()\ntype 3: view()\n");



for(;;){



scanf("%d", &type);




if(type == 1){



printf("[PUSH]\n");


printf("값을 입력하세요: ");



scanf("%d", &push_input);



push(push_input);



}






if(type == 2){


printf("[POP]\n");


pop();



}






if(type == 3){




printf("[VIEW]\n");


view();



}



}



}


*/



/*


#include <stdio.h>



int front = 0;


int rear = 0;



int stack[5] = {0};




void push(int p){





if(front - rear == 4 || front - rear == -1){


front++;


printf("Stack is full (Front: %d, Rear: %d)\n\n", front, rear);



front--;



return;



}




if(front > 4) {


front = 0;


stack[0] = p;


front++;


printf("Front: %d, Rear: %d\n\n", front, rear);


return;


}




front++;


printf("Front: %d, Rear: %d\n\n", front, rear);


stack[front-1] = p;




return;



}




void pop(){




if(front == rear){




printf("Stack is empty(Front: %d, Rear: %d)\n\n", front, rear);




return;



}




rear++;




if(rear == 5){




stack[rear-1] = 0;


rear = 0;


printf("Front: %d, Rear: %d\n\n", front, rear);


return;




}








stack[rear-1] = 0;


printf("Front: %d, Rear: %d\n\n", front, rear);


return;



}




void view(){




for(int i=4;i>-1;i--){



printf("%d 번째 칸: %d\n", i, stack[i]);



}


printf("Front: %d, Rear: %d\n\n", front, rear);


return;



}




int main(){



int type;



int push_input;



printf("type 1: push()\ntype 2: pop()\ntype 3: view()\n");



for(;;){



scanf("%d", &type);




if(type == 1){



printf("[PUSH]\n");


printf("값을 입력하세요: ");



scanf("%d", &push_input);



push(push_input);



}






if(type == 2){


printf("[POP]\n");


pop();



}






if(type == 3){




printf("[VIEW]\n");


view();



}



}



}


*/


/*

#include <stdio.h>



int front = 0;


int rear = 0;


int f = 0;


int stack[5] = {0};




void push(int p){



if(f == 5){

printf("Stack is full\n");

printf("Front: %d, Rear: %d\n\n", front, rear);

return;

}


if (front == 5){

front = 1;

stack[0] = p;

f++;

printf("Front: %d, Rear: %d\n\n", front, rear);

return;

}


stack[front++] = p;

f++;

printf("Front: %d, Rear: %d\n\n", front, rear);


return;



}




void pop(){



if(f == 0){

printf("Stack is empty(Front: %d, Rear: %d)\n\n", front, rear);

return;

}


if(rear == 5){

rear = 1;

stack[0] = 0;

f--;

printf("Front: %d, Rear: %d\n\n", front, rear);

return;

}


stack[rear++] = 0;

f--;

printf("Front: %d, Rear: %d\n\n", front, rear);

return;


}




void view(){




for(int i=4;i>-1;i--){



printf("%d 번째 칸: %d\n", i, stack[i]);



}


printf("Front: %d, Rear: %d\n\n", front, rear);


return;



}




int main(){



int type;



int push_input;



printf("type 1: push()\ntype 2: pop()\ntype 3: view()\n");



for(;;){



scanf("%d", &type);




if(type == 1){



printf("[PUSH]\n");


printf("값을 입력하세요: ");



scanf("%d", &push_input);



push(push_input);



}






if(type == 2){


printf("[POP]\n");


pop();



}






if(type == 3){




printf("[VIEW]\n");


view();



}



}



}

//노드 추가 (.)

Node myNode = NULL;

myNode = (Node)malloc(sizeof(Node));

myNode.data = 10;


// 이후 노드 추가

newNode = (Node*)malloc(sizeof(Node));

newNode->data = 100;

newNode->next = NULL;


cur = head;

while(cur->next!=NULL)

{

cur = cur->next;

}

cur->next = newNode;

view(head);

*/


//Linked List



#include <stdio.h>

#include <stdlib.h>


typedef struct _node{

int data;

struct _node * next;

}Node;


int main()

{

Node *head = NULL;

Node *tail = NULL;

Node *cur = NULL;


Node *newNode = NULL;

int newData;

ListInit();

//최초 노드 추가 ( -> )



while(1)

{

scanf("%d", &newData);

if(newData < 1) {

break;

}

newNode = (Node*)malloc(sizeof(Node));

newNode->data = newData;

newNode->next = NULL;


if (head == NULL)

head = newNode;

else

tail->next = newNode;


tail = newNode;


}


printf("\n입력 받은 데이터의 전체 출력!\n");


if(head == NULL){

printf("저장된 값이 존재하지 않습니다. \n");

}


else{


cur = head;

printf("Linked List : ");


printf("%d -> ", cur->data);


while(cur->next != NULL){

cur = cur->next;

printf("%d -> ", cur->data);

}



}

printf("\n\n");



if(head == NULL){

return 0;

}


else{

Node * delNode = head;

Node * delNextNode = head -> next;


printf("%d 삭제됨 \n", head->data);

free(delNode);


while(delNextNode != NULL){

delNode = delNextNode;

delNextNode = delNextNode->next;


printf("%d 삭제됨 \n", delNode->data);

free(delNode);

}

}



return 0;

}

1회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page