top of page

소스 코드 제출

공개·회원 72명

손유준손유준

20251213

#include <stdio.h>

#include <malloc.h>

#include <string.h>

#include <stdlib.h>


typedef struct node {

int data;

struct node *link;

} Node;


int k;

char c[100];

Node *head = NULL;

Node *tail = NULL;


void view()

{

Node *p = head;

printf("[ ");

while (p != NULL)

{

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

p = p->link;

}

printf("]\n");

}


void pop()

{

if (head == NULL)

{

printf("NO DATA\n");

return;

}

if (head == tail)

{

head = NULL;

tail = NULL;

return;

}

Node *p = head;

while (p != NULL)

{

if (p->link->link == NULL)

{

p->link = NULL;

tail = p;

return;

}

p = p->link;

}

}


void append(int value)

{

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

x->data = value;

x->link = NULL;

if (head == NULL)

{

head = x;

tail = x;

}

else

{

tail->link = x;

tail = x;

}

}


void insert(int i, int x)

{

//head tail에 값이 들어있으면 안 되는데 이상하게 해 놨으니 집에서 그거 수정하셈

return;

}


int main()

{

while (1)

{

fgets(c, sizeof(c), stdin);

if (!strcmp(c, "view\n"))

{

view();

}

else if (!strcmp(c, "pop\n"))

{

pop();

}

else if (sscanf(c, "append(%d)", &k) == 1)

{

append(k);

}

}


return 0;

}



//#include<stdio.h>

//

//char data[15] = {};

//

//void tree(int n) {

// if(n>7) return;

//

// tree(n*2);

// tree(n*2+1);

// printf("%c ", data[n]);

// // ABCDG

//}

//

//int main() {

//

// scanf("%s", &data[1]);

//

// for(int i=0; i<strlen(data); i++) {

// printf("%c ", data[i]);

// }

// printf("\n");

// tree(1);

//}

///*

// A

// B C

// D E F G

//

// // ABD

//

//*/

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