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
生成AI
takenawa
0
5k
検索/ディスプレイ/SNS
takenawa
0
5k
Data Physicalisation - Lecture 9 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
430
諸外国の理科カリキュラムにおけるビッグアイデアの構造比較
arumakan
0
310
仮説の取扱説明書/User_Guide_to_a_Hypothesis
florets1
4
300
ThingLink
matleenalaakso
28
4.1k
第1回大学院理工学系説明会|東京科学大学(Science Tokyo)
sciencetokyo
PRO
0
3.8k
マネジメント「される側」 こそ覚悟を決めろ
nao_randd
10
5.3k
社外コミュニティと「学び」を考える
alchemy1115
2
170
2025年度春学期 統計学 第1回 イントロダクション (2025. 4. 10)
akiraasano
PRO
0
170
生成AIとの上手な付き合い方【公開版】/ How to Get Along Well with Generative AI (Public Version)
handlename
0
470
Gesture-based Interaction - Lecture 6 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
1.7k
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
Adopting Sorbet at Scale
ufuk
77
9.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Why You Should Never Use an ORM
jnunemaker
PRO
57
9.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Site-Speed That Sticks
csswizardry
10
660
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
490
Fireside Chat
paigeccino
37
3.5k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
GraphQLとの向き合い方2022年版
quramy
48
14k
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);