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
72
ОПК, семинар №6
Массивы и списки
Ilya
March 05, 2015
Tweet
Share
More Decks by Ilya
See All by Ilya
Программирование на ЯВУ, семинар 3
ilya
0
130
Программирование на ЯВУ, семинар 2
ilya
0
68
ОПК, семинар №8
ilya
0
49
ОПК, семинар №4
ilya
0
100
ОПК, семинар №2
ilya
0
74
Other Decks in Education
See All in Education
Multimodal Interaction - Lecture 3 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
1.1k
【滋賀大学データサイエンス学部】PropTech(不動産テック)における AI・データサイエンス活用
takehikohashimoto
0
4.1k
Project Sprint 学生版(入門編)
copilot
PRO
0
190
Animaatiot opetuksessa
matleenalaakso
0
3.1k
合理的配慮を知るワークショップ/Understanding Reasonable Accommodations (Workshop)
freee
2
1.5k
Microsoft Office 365
matleenalaakso
0
1.5k
MonacaEducation導入手引き2024年第1版
asial_edu
1
170
「小・中・高等学校における情報教育の体系的な学習を目指したカリキュラムモデル基本方針」
codeforeveryone
0
1.4k
20240319AJG
tosseto
0
310
Часто задаваемые вопросы
pnuslide
0
25k
ISMSってどんなもの?
fbei_ot
0
180
Design Guidelines and Principles - Lecture 7 - Information Visualisation (4019538FNR)
signer
PRO
0
1.7k
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
242
1.2M
Designing Experiences People Love
moore
136
23k
Building a Scalable Design System with Sketch
lauravandoore
457
32k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
65
14k
KATA
mclloyd
16
12k
Faster Mobile Websites
deanohume
300
30k
Embracing the Ebb and Flow
colly
80
4.2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
12
1.5k
Rebuilding a faster, lazier Slack
samanthasiow
74
8.2k
The MySQL Ecosystem @ GitHub 2015
samlambert
244
12k
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);