Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ОПК, семинар №6
Search
Ilya
March 05, 2015
Education
0
74
ОПК, семинар №6
Массивы и списки
Ilya
March 05, 2015
Tweet
Share
More Decks by Ilya
See All by Ilya
Программирование на ЯВУ, семинар 3
ilya
0
160
Программирование на ЯВУ, семинар 2
ilya
0
72
ОПК, семинар №8
ilya
0
54
ОПК, семинар №4
ilya
0
110
ОПК, семинар №2
ilya
0
85
Other Decks in Education
See All in Education
View Manipulation and Reduction - Lecture 9 - Information Visualisation (4019538FNR)
signer
PRO
1
2.1k
SkimaTalk Teacher Guidelines
skimatalk
0
800k
Gaps in Therapy in IBD - IBDInnovate 2025 CCF
higgi13425
0
500
著作権と授業に関する出前講習会/dme-2025-05-01
gnutar
0
200
教員向け生成AI基礎講座(2025年3月28日 東京大学メタバース工学部 ジュニア講座)
luiyoshida
1
620
実務プログラム
takenawa
0
8k
OJTに夢を見すぎていませんか? ロールプレイ研修の試行錯誤/tryanderror-in-roleplaying-training
takipone
1
170
ビジネスモデル理解
takenawa
0
8.1k
Visualisation Techniques - Lecture 8 - Information Visualisation (4019538FNR)
signer
PRO
0
2.4k
『会社を知ってもらう』から『安心して活躍してもらう』までの プロセスとフロー
sasakendayo
0
240
自己紹介 / who-am-i
yasulab
PRO
3
5.2k
Linuxのよく使うコマンドを解説
mickey_kubo
1
240
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.2k
KATA
mclloyd
30
14k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Raft: Consensus for Rubyists
vanstee
140
7k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Speed Design
sergeychernyshev
32
1k
The Straight Up "How To Draw Better" Workshop
denniskardys
235
140k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.6k
For a Future-Friendly Web
brad_frost
179
9.8k
Six Lessons from altMBA
skipperchong
28
3.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
830
Transcript
Работа с меняющимися массивами
void replace(char* source, const char* old, const char* new) {
// ... } char* replace("Hello, World!", "!", "?"); H e l l o , W o r l d ! H e l l o , W o r l d !
void replace(char* source, const char* old, const char* new) {
// ... } char* replace("Hello, World!", "World", "Universe"); H e l l o , W o r l d ! H e l l o , U n i v e r s e !
void replace(char* source, const char* old, const char* new) {
// ... } char* replace("Hello, World!", "World", "Me"); H e l l o , W o r l d ! H e l l o , M e !
char* replace(const char* source, const char* old, const char* new)
{ char* result; int size_diff = count(source, old) * (strlen(new) - strlen(old)); size_t resulting_length = strlen(source) + size_diff; result = calloc(resulting_length, sizeof(char)); // Замена return result; }
H e l l o , W o r l
d ! H e l l o , M e ! char* replace("Hello, World!", "World", "Me");
H e l l o , W o r l
d ! char* replace("Hello, World!", "World", "Universe"); H e l l o , U n i v e r s e !
1 2 3 4 5 6 8 9 10 7
int* array = calloc(20, sizeof(int)); 1 2 3 4 5 6 8 9 10 7 int *new_array = calloc(40, sizeof(int)); memcpy(new_array, array, 40 * sizeof(int)); free(array); 1 2 3 4 5 6 8 9 10 7 1 2 3 4 5 6 8 9 10 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 memcpy
Списки, Зачем?
void insert_sorted(int *array, int number); int array[20]; int input; do
{ scanf("%d", &input); insert_sorted(&array, input); } while(1); < 1 < 2 … < 60 1 2 3 4 10 20 40 50 60 30
void insert_sorted(int *array, int number); int array[20]; int input; do
{ scanf("%d", &input); insert_sorted(&array, input); } while(1); < 1 < 2 … < 60 1 2 3 4 10 20 40 50 60 30 < 5
void insert_sorted(int *array, int number); int array[20]; int input; do
{ scanf("%d", &input); insert_sorted(&array, input); } while(1); < 1 < 2 … < 60 1 2 3 4 10 20 40 50 60 30 < 5 5
Односвязные списки typedef struct ListNode ListNode; typedef struct ListNode* pListNode;
ListNode { int value; pListNode next; }; 5 10 NULL 15 NULL
5 10 NULL pListNode new_node(int value) { pListNode node =
(pListNode) malloc( sizeof(ListNode)); if (node == NULL) { return NULL; } node->value = value; node->next = NULL; return node; } new_node(5); new_node(10);
5 10 NULL void link_nodes(pListNode first, pListNode second) { first->next
= second; // (*first).next }
5 10 NULL void link_nodes(pListNode first, pListNode second) { first->next
= second; // (*first).next }
5 10 NULL ListNode nodes[3] = {new_node(5), new_node(10), new_node(15)}; 15
NULL
5 10 NULL ListNode nodes[3] = {new_node(5), new_node(10), new_node(15)}; link_nodes(&nodes[0],
&nodes[1]); link_nodes(&nodes[1], &nodes[2]); do { printf("Node %d\n", point->value); point = point->next; } while (point != NULL); > Node 5 > Node 10 > Node 15 15 NULL
void insert_node(pListNode first, pListNode second) { pListNode third = first->next;
first->next = second; second->next = third; } int main() { pListNode head, point, intermediate; head = new_node(5); link_nodes(head, new_node(10)); insert_node(head, new_node(7)); ... } 5 NULL
void insert_node(pListNode first, pListNode second) { pListNode third = first->next;
first->next = second; second->next = third; } int main() { pListNode head, point, intermediate; head = new_node(5); link_nodes(head, new_node(10)); insert_node(head, new_node(7)); ... } 5 NULL 5 10 NULL
void insert_node(pListNode first, pListNode second) { pListNode third = first->next;
first->next = second; second->next = third; } int main() { pListNode head, point, intermediate; head = new_node(5); link_nodes(head, new_node(10)); insert_node(head, new_node(7)); ... } 5 NULL 5 10 NULL 5 10 NULL 7 NULL
int main() { pListNode head, point, intermediate; head = new_node(5);
point = head; link_nodes(head, new_node(10)); insert_node(head, new_node(7)); do { printf("Node %d\n", point->value); point = point->next; } while (point != NULL); } > Node 5 > Node 7 > Node 10 5 NULL 5 10 NULL 5 10 NULL 7 NULL
Двусвязные списки typedef struct ListNode ListNode; typedef struct ListNode* pListNode;
struct ListNode { int value; pListNode next, prev; }; 5 10 NULL 15 NULL
Двусвязные списки typedef struct ListNode ListNode; typedef struct ListNode* pListNode;
struct ListNode { int value; pListNode next, prev; }; 5 10 NULL 15 NULL
struct DoubleLinkedList { pListNode head, tail; } void free_list(DoubleLinkedList);