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
技術勉強会 〜 OAuth & OIDC 入門編 / 20250528 OAuth and OIDC
oidfj
5
1.2k
諸外国の理科カリキュラムにおけるビッグアイデアの構造比較
arumakan
0
320
GitHubとAzureを使って開発者になろう
ymd65536
1
110
第1回大学院理工学系説明会|東京科学大学(Science Tokyo)
sciencetokyo
PRO
0
3.8k
技術文章を書くための執筆技術と実践法(パラグラフライティング)
hisashiishihara
18
6.5k
OpenSourceSummitJapanを運営してみた話
kujiraitakahiro
0
710
Design Guidelines and Principles - Lecture 7 - Information Visualisation (4019538FNR)
signer
PRO
0
2.4k
アウトプット0のエンジニアが半年でアウトプットしまくった話 With JAWS-UG
masakiokuda
2
310
Tutorial: Foundations of Blind Source Separation and Its Advances in Spatial Self-Supervised Learning
yoshipon
1
120
推しのコミュニティはなんぼあってもいい / Let's join a lot of communities.
kaga
2
1.7k
Sponsor the Conference | VizChitra 2025
vizchitra
0
550
2025年度春学期 統計学 第4回 データを「分布」で見る (2025. 5. 1)
akiraasano
PRO
0
100
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
125
52k
The World Runs on Bad Software
bkeepers
PRO
69
11k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
Faster Mobile Websites
deanohume
307
31k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
A designer walks into a library…
pauljervisheath
207
24k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
17
950
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);