You are on page 1of 5

Struct Student{ // User-defined data type

String Name;
String ID;
Float GPA;
Int Smstr;
};
Student S[26]; S[2].GPA; S[1].ID;
Student *p; p = S; (p+2)🡪GPA; (p+1)🡪ID;
Name ID GPA Smstr

Fulan 00120190001 3.2 4


John 00120190017 3.4 4

Jane 00120190020 3.0 4


Wahyuni 00120190023 3.45 4

Rizaldi 00120190002 3.35 4


Zidane 3.25

Disadvantage? 🡪 Linked List

Struct Student{ // User-defined data type


String Name;
String ID; Name ID Ne
Float GPA; GPA Smstr
xt
Int Smstr;
Student *next;
};
Wahy
xx..23 Ne
uni
Student *head = 0; 3.45 4
xt

xxx.1 xx…
John Ne Fulan xx..01 Jane Ne
7 Ne 20
xt xt xt
3.4 4 3.2 4 3.0 4
W xx
xx. Ne
Jo
3. xx.
Fu
Ne
ah
3. x.1
4 Ne
3.
.2
4 hn
xt
4 la
.0
4
yu
xt
45 7 xt
2
3 n
1
ni

xx.
Ri
Ne
3.
zal
.2
4
xt
35
di
0

Wahy xxx.1 xx…


xx..23 John Ne Fulan xx..01 Jane
uni Ne 7 Ne 20
xt xt xt 3.0 4
3.45 4 3.4 4 3.2 4
Struct Student{ // User-defined data type
String Name;
String ID; Name ID Ne
Float GPA; GPA Smstr
xt
Int Smstr;
Student *next;
};

Student *Insert(string n,string d,float g,int s,Student *h)


{
Student *cur = h,*prev = 0;
While(cur && cur->GPA >= g){
prev = cur;
cur = cur->next;
}
Student *temp = new Student;
temp->Name = n;
...
If(prev){ // in the middle and at the end
temp->next = prev->next;
prev->next = temp;
}else{
temp->next = cur;
h = temp;
}
Return h;
}

You might also like