전체 글 (127) 썸네일형 리스트형 문과생이 이해한 스택(동적, 구조체) 출처 : + 학교 수업 #include #include typedef int element; typedef struct node { element data; struct node* link; }node; node* top = NULL; void push(element value) { node* new_node = (node*)malloc(sizeof(node)); if (new_node == NULL) { fprintf(stderr, "메모리 할당 에러\n"); return; } else { new_node->data = value; new_node->link = top; top = new_node; } } element pop() { if (top == NULL) { fprintf(stderr, "스택.. 문과생이 이해한 스택(정적, 구조체) 출처 : + 학교 수업 #include #include #define MAX 100 typedef struct { int student_no; char name[MAX]; char address[MAX]; }element; element stack[MAX]; int top = -1; int is_empty() { return top == -1; } int is_full() { return top == MAX - 1; } void push(element item) { if (is_full()) { fprintf(stderr, "스택 포화 에러\n"); return; } else stack[++top] = item; } element pop() { if (is_empty()) { fprintf(stderr,.. 문과생이 이해한 이중 연결리스트 출처 : 깃 허브 github.com/Shinsungjun/VScodecommit/blob/master/DataStructure/LinkedList/DoublyLinkedList1.c Shinsungjun/VScodecommit first VS code commit. Contribute to Shinsungjun/VScodecommit development by creating an account on GitHub. github.com 이 코드를 가지고 공부햇다. 본 코드는 뒤에서만 추가가 가능하길래 앞에서도 추가할 수 있는 코드를 추가했다. #include #include typedef struct NODE { //여기에 NODE안 써줘면 에러 struct NODE* llink; int data; st.. 문과생이 이해한 원형 연결리스트 출처 : + 학교 수업 #include #include typedef struct { int data; struct node* link; }node; void print_node(node* head) { node* p; if (head == NULL) return; p = head->link; do { printf("%d -> ", p->data); p = p->link; } while (p != head); printf("%d->", p->data); } node* insert_first(node* head, int data) { node* p = (node*)malloc(sizeof(node)); p->data = data; if (head == NULL) { head = p; p->link = he.. [3장] 도전 문제 package lecture3; import java.util.*; public class p160 { public static void main(String[] args) { Scanner s=new Scanner(System.in); int hint1=0; int hint2=99; int num=0; Random r = new Random(); int k=r.nextInt(100); System.out.println("수를 결정하였습니다. 맞추어 보세요."); while(true) { for(int i=1; ;i++) { System.out.println(hint1 + "-" + hint2); System.out.print(i+">>"); num=s.nextInt(); if(numk) { System.. 검색해도 잘 안 나오는 자바 단축키 1. 전체 tab 쓰기- ctrl + a / ctrl+shift+f 일단 임의로 코드를 들쭉날쭉 썼다. ctrl+a로 전체 코드를 잡고, ctrl+shift+f를 누르면 전체 자동 들여쓰기가 된다. 요로코롬 예쁘게 들여쓰기가 된다. 2. 한 줄 바로 삭제- ctrl + d 만약 23줄을 삭제하고 싶으면 ctrl+d를 누르면 된다. 3. main 문 자동 생성- main / ctrl+스페이스 python을 배우다가 java를 배우니까 main문 쓰는 게 꽤 골치아프다. 사진과 같이 main이라고 쓰고 ctrl+스페이스바를 누르면 다음 사진과 같이 뜨는데 이때 enter키를 누르면 바로 메인문이 생성된다. 4. print문 자동 생성- sysout / ctrl+스페이스 3번과 동일하다. 여기서는 printf.. 문과생이 이해한 단일 연결리스트(이중 포인터 사용) #include typedef struct { int data; struct node* link; }node; node* insert_first(node** head, int x) { node* p = (node*)malloc(sizeof(node)); p->data = x; p->link = head; head= p; } int main() { node* head = NULL; //데이터 삽입 및 출력 for (int i = 0; i < 5; i++) { head = insert_first(&head,i); //반환된 head 포인터를 저장. 아니면 null값만 출력됨 print_node(&head); } return 0; } 이중 포인터는 포인터의 포인터를 저장한다. 그래서 head값을 굳이 retu.. 문과생이 이해한 단일 연결 리스트(기타 연산- 합병, 역순, 출력/순회, 탐색) 출처 : + 학교 수업 #전체 코드 #include #include typedef struct { int data; struct node* link; }node; node* insert_first(node* head, int x) { node* p = (node*)malloc(sizeof(node)); p->data = x; p->link = head; //head는 노드 생성을 안했으니까 head->link 연산이 안 됨 head= p; return head; } node* insert(node* head, node* pre, int s) { node* p = (node*)malloc(sizeof(node)); p->data = s; p->link = pre->link; pre->link = p; re.. 이전 1 ··· 12 13 14 15 16 다음