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
JOAI2025講評 / joai2025-review
upura
0
160
America and the World
oripsolob
0
510
Tangible, Embedded and Embodied Interaction - Lecture 7 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
1.7k
Data Management and Analytics Specialisation
signer
PRO
0
1.4k
OJTに夢を見すぎていませんか? ロールプレイ研修の試行錯誤/tryanderror-in-roleplaying-training
takipone
1
160
自己紹介 / who-am-i
yasulab
PRO
3
5.2k
SkimaTalk Introduction for Students
skimatalk
0
380
OpenSourceSummitJapanを運営してみた話
kujiraitakahiro
0
710
2025年度春学期 統計学 第5回 分布をまとめるー記述統計量(平均・分散など) (2025. 5. 8)
akiraasano
PRO
0
120
Pydantic(AI)とJSONの詳細解説
mickey_kubo
0
110
Gaps in Therapy in IBD - IBDInnovate 2025 CCF
higgi13425
0
500
推しのコミュニティはなんぼあってもいい / Let's join a lot of communities.
kaga
2
1.8k
Featured
See All Featured
Facilitating Awesome Meetings
lara
54
6.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Raft: Consensus for Rubyists
vanstee
140
7k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
810
Building a Scalable Design System with Sketch
lauravandoore
462
33k
It's Worth the Effort
3n
185
28k
Adopting Sorbet at Scale
ufuk
77
9.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.9k
Embracing the Ebb and Flow
colly
86
4.7k
Building Adaptive Systems
keathley
43
2.6k
Faster Mobile Websites
deanohume
307
31k
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);