Last active
May 22, 2017 15:20
-
-
Save derohimat/8c87b43b9b724b118b687e99fde76bf1 to your computer and use it in GitHub Desktop.
dynamic struct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct NilaiMatKul { | |
char nim[11]; | |
char nama[30]; | |
char nilai[2]; | |
}; | |
struct element { | |
NilaiMatKul matKul; | |
struct element *next; | |
}; | |
struct list { | |
struct element *first; | |
}; | |
void createList(list *l) { | |
(*l).first = NULL; | |
} | |
void printElement(list l) { | |
if (l.first != NULL) { | |
element *item; | |
item = l.first; | |
while (item != NULL) { | |
cout << "NIM : " << item->matKul.nim << endl; | |
cout << "Nama : " << item->matKul.nama << endl; | |
cout << "Nilai : " << item->matKul.nilai << endl; | |
cout << "========================================" << endl; | |
item = item->next; | |
} | |
} | |
} | |
void addFirst(char nim[], char nama[], char nilai[], list *l) { | |
element *item; | |
item = (element *) malloc(sizeof(element)); | |
strcpy(item->matKul.nim, nim); | |
strcpy(item->matKul.nama, nama); | |
strcpy(item->matKul.nilai, nilai); | |
item->next = (*l).first; | |
(*l).first = item; | |
item = NULL; | |
} | |
void addLast(char nim[], char nama[], char nilai[], list *l) { | |
} | |
void addAfter(element *prev, char nim[], char nama[], char nilai[], list *l) { | |
} | |
int main() { | |
struct list l; | |
createList(&l); | |
addFirst("0616103020", "Deni", "90", &l); | |
addFirst("0616103021", "Rohimat", "90", &l); | |
printElement(l); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment