-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
106 lines (77 loc) · 2.05 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
02.03.2021
Dinamik Hafiza Tahsisi ile Array ve LinkedList Kullanim Örneði
*/
#include <stdio.h>
#include <stdlib.h>
#include <mem.h>
#pragma pack(1)
typedef struct TESTNODE {
char szAd[21];
char szSoyad[21];
void *pNext;
}TESTNODE;
/*
0 -> 1 -> 2
Linked List TESTNODE | .............. | TESTNODE | ............. | TESTNODE
0 1 2
Array TESTNODE | TESTNODE | TESTNODE
*/
TESTNODE *pRoot = NULL;
void* AddHeadItem( char *szAd , char *szSoyad ) {
TESTNODE *pNew = malloc( sizeof( TESTNODE ) );
if( pNew != NULL ) {
memset( pNew , 0 , sizeof( TESTNODE ) );
strncpy(pNew->szAd , szAd , 20 );
strncpy(pNew->szSoyad , szSoyad , 20 );
pNew->pNext = pRoot;
pRoot = pNew;
}
return pNew;
}
/*
void* AddTailItem( char *szAd , char *szSoyad ) {
}
*/
void ClearList() {
TESTNODE *pSel = pRoot;
while( pSel != NULL ) {
pRoot = pSel->pNext;
free( pSel );
pSel = pRoot;
}
return;
}
int main()
{
//Linked List Örnegi
AddHeadItem("Ahmet" , "SEZA");
AddHeadItem("Mehmet" , "YAHYA");
AddHeadItem("Cevdet" , "SARI");
AddHeadItem("Arif" , "KARAKILIC");
AddHeadItem("Alihan" , "SARAC");
AddHeadItem("Sule" , "KOC");
TESTNODE *pNode = pRoot;
while( pNode != NULL ) {
printf( "Ad Soyad : %s %s\n" , pNode->szAd , pNode->szSoyad );
pNode = pNode->pNext;
}
ClearList();
//Array Örnegi Random Access Erisimi
/*
TESTNODE *p = (TESTNODE *)malloc( sizeof( TESTNODE ) * 1000 );
if( p != NULL ) {
memset( p , 0 , sizeof( TESTNODE ) * 1000 );
for( int i = 0; i < 800; i++ ) {
sprintf( p[i].szAd , "Ad %d" , (i+1) );
sprintf( p[i].szSoyad , "Soyad %d" , (i+1) );
}
for( int i = 80; i < 90; i++ ) {
printf( "Ad Soyad : %s %s\n" , p[i].szAd , p[i].szSoyad );
}
free( p );
}
*/
printf("Sizeof TESTNODE = %d byte\n" , sizeof( TESTNODE ));
return 0;
}