티스토리 뷰
연결리스트(LinkedList)
-예제를 통한 연결리스트 연습
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | #include <stdio.h> #include <malloc.h> typedef int element; typedef struct node { element data; node* link; }node; node *head, *temp; int N, M, x, y; int password[1000], arr[1000]; void initList() { head = (node *)malloc(sizeof(node)); head->link = NULL; } void insertNode(int data) { node *newnode; newnode = (node *)malloc(sizeof(node)); newnode->data = data; temp = head; if (head->link == NULL) { newnode->link = NULL; head->link = newnode; return; } while (temp->link != NULL) temp = temp->link; newnode->link = NULL; temp->link = newnode; } void insertpos(int pos, int data) { node *newnode; newnode = (node *)malloc(sizeof(node)); newnode->data = data; temp = head; for (int i = 0; i < pos; i++) temp = temp->link; newnode->link = temp->link; temp->link = newnode; } void printList() { temp = head; for (int i = 0; i < 10; i++) { printf("%d ", (temp->link)->data); temp = temp->link; } } void clearList() { free(head); free(temp); } int main() { for (int tc = 1; tc <= 10; tc++) { char ins = 0; initList(); scanf("%d\n", &N); for (int i = 0; i < N; i++) { scanf("%d ", &password[i]); insertNode(password[i]); } scanf("%d\n", &M); //명령어 수 for (int i = 0; i < M; i++) { if (i == 0) scanf("%c %d %d", &ins, &x, &y); else scanf(" %c %d %d", &ins, &x, &y); for (int j = 0; j < y; j++) { scanf(" %d", &arr[j]); insertpos(x + j, arr[j]); } } printf("#%d ", tc); printList(); printf("\n"); clearList(); } return 0; } | cs |
'STUDY > 자료구조(Data Structures)' 카테고리의 다른 글
자료구조 •String 숫자를 Int로 변환(스트링->정수 변환)• (0) | 2017.12.30 |
---|---|
자료구조 •트리(Tree) -구조체 배열• (0) | 2017.12.29 |
자료구조 •트리(Tree) 개념• (0) | 2017.12.27 |
자료구조 •연결리스트-2(LinkedList)• (0) | 2017.12.27 |
자료구조 •배열리스트(ArrayList)• (0) | 2017.12.27 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- kmp 알고리즘
- 연결리스트
- string
- 다이어리
- int변환
- string변환
- 컴퓨터네트워크
- atoi()
- 알고리즘개념
- LinkedList
- 겨울방학
- string개념
- string int로 변환
- 네트워크
- Algorithms
- 해싱 충돌
- datastructures
- 패턴 매칭
- DataStructure
- 자료구조
- 보이어-무어
- 알고리즘
- 시험준비
- 계획
- Tree
- 트리
- c언어
- stringint
- open address
- string숫자
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함