Struct Node
Struct Node
if(sll.pHead == int
NULL){ CountKLinkedList(List Node *GetNode(int x)
sll, int k){ {
sll.pHead =
NewNode; Node *p = Node *p = new
sll.pHead; Node;
sll.pTail =
NewNode; int cnt = 0; if(p == NULL)
return NULL;
}else{ while(p != NULL){
sll.pTail->pNext if(p->data == k)
= NewNode; { p->data = x;
sll.pTail = cnt++; p->pNext = NULL;
NewNode;
} return p;
}
p = p->pNext; }
}
}
return cnt; void InsertLast(List
void ShowList(List sll) &sll, int k){
}
{
Node *NewNode =
struct Node
Node *p = GetNode(k);
sll.pHead; {
if(NewNode ==
while(p != NULL){ int data; NULL) return;
printf("%d ", p- Node* pNext;
>data);
}; if(sll.pHead ==
p = p->pNext; NULL){
sll.pHead = return temp->data; void InsertLast(List
NewNode; &sll, int k){
}
sll.pTail = Node *NewNode =
struct Node
NewNode; GetNode(k);
{
}else{ if(NewNode ==
int data; NULL) return;
sll.pTail->pNext
= NewNode; Node* pNext;
sll.pTail = }; if(sll.pHead ==
NewNode; NULL){
} sll.pHead =
struct List NewNode;
}
{ sll.pTail =
Node* pHead; NewNode;
void AppendList(List
Node* pTail; }else{
&sll, int V[], int n){
}; sll.pTail->pNext
for(int i=0;i<n;i++)
= NewNode;
{
sll.pTail =
InsertLast(sll, void Init(List &sll){ NewNode;
V[i]);
sll.pHead = sll.pTail }
} = NULL;
}
} }
sll.pTail = NULL; }
void AppendList(List
} &sll, int V[], int n){
for(int i=0;i<n;i++) if(p == {
{ sll.pTail){
Student data;
InsertLast(sll, sll.pTail =
Node* link;
V[i]); pos;
};
} }
} delete p;
struct ListStudent
p = pos-
>pNext; {
int
RemoveNodesK(List } Node* first;
&sll, int k){
cnt++; Node* last;
int cnt = 0;
}else{ };
Node *p =
pos = p;
sll.pHead;
p = p->pNext; void
Node *pos = NULL;
Initial(ListStudent &l)
}
{
}
while(p != NULL){ l.first = l.last =
return cnt; NULL;
if(p->data == k)
{ } }
if(p == struct BirthDay{
sll.pHead){
int day; void
sll.pHead = InsertLast(ListStudent
p->pNext; int month;
&l, Student &st){
if(sll.pHead double year;
Node *p = new
== NULL){ }; Node;
sll.pTail = p->data = st;
NULL;
struct Student{ p->link = NULL;
}
string ID;
delete p;
string Name; if(l.first == NULL){
p=
sll.pHead; string Gender; l.first = l.last =
p;
}else{ BirthDay Born;
}else{
pos->pNext };
= p->pNext; l.last->link = p;
l.last = p;
struct Node
} p->data = st;
} struct Student{ p->link = NULL;
string ID;
void string Name; if(l.first == NULL){
ShowListStudent(cons
string Gender; l.first = l.last =
t ListStudent &list) {
p;
BirthDay Born;
Node* current =
}else{
list.first; };
p->link = l.first;
while (current !=
nullptr) { l.first = p;
struct Node
cout << current- }
>data.ID << '\t' {
}
<< current- Student data;
>data.Name << '\t' Node* link;
<< current- void
};
>data.Gender << '\t' ShowListStudent(ListS
tudent list) {
<< current-
>data.Born.month struct ListStudent Node* current =
<< '/' list.first;
{
<< current- while (current !=
Node* first; nullptr) {
>data.Born.day << '/'
Node* last; cout << current-
<< current-
>data.Born.year << }; >data.ID << '\t'
endl; << current-
>data.Name << '\t'
void
current = Initial(ListStudent &l) << current-
current->link; { >data.Gender << '\t'
InsertLast(l, st); } }
} // CODE HERE
void int so;
ShowStudentHeads(c
fscanf(fp, "%d",
onst ListStudent &list,
&so);
file.close(); int n) {
printf("%d\n", so);
} Node* current =
list.first;
int count = 0;
fclose(fp); if (file == NULL) {
} fclose(fp); printf("Không
thể mở file!\n");
void ReadChar(char }
*filename){ return;
#include <stdio.h>
FILE *fp = }
void FileSum(char
fopen(filename, "r");
*fileName) { char
if(fp == NULL){ line[MAX_LINE_LENGT
FILE *file =
H];
printf("Error! fopen(fileName, "r");
Could not open file"); // Đọc từng dòng và
if (file == NULL) {
xuất ra màn hình
exit(1);
printf("Error!
while (fgets(line,
} Could not open file\
sizeof(line), file) !=
n");
NULL) {
return;
char kytu; printf("%s", line);
}
fscanf(fp, "%c", }
&kytu); int number;
fclose(file);
printf("%c", kytu); int sum = 0;
}
while (fscanf(file,
void
"%d", &number) ==
fclose(fp); ReadEleArrFile(const
1) {
char* filename) {
}
sum +=
FILE* file =
void ReadChar(char number;
fopen(filename, "rb");
*filename){
}
if (file == NULL) {
FILE *fp =
fclose(file);
fopen(filename, "r"); printf("Không
printf("%d\n", thể mở file %s\n",
if(fp == NULL){ filename);
sum);
printf("Error! return;
}
Could not open file");
#define }
exit(1);
MAX_LINE_LENGTH
int number;
} 256
while
void
(fread(&number,
ShowContent(const
char kytu; sizeof(int), 1, file)) {
char *fileName) {
fscanf(fp, "%c", printf("%d ",
FILE *file =
&kytu); number);
fopen(fileName, "r");
printf("%c", kytu); }
fclose(file); FILE* file = void
fopen(filename, "rb"); ShowBalance(const
}
char* filename) {
if (file == NULL) {
int
FILE* file =
SumNegEleArrFile(con printf("Không
fopen(filename, "r");
st char* filename) { thể mở file %s\n",
filename); if (file == NULL) {
FILE* file =
fopen(filename, "rb"); return -8080; printf("Không
thể mở file %s\n",
if (file == NULL) { }
filename);
printf("Không fseek(file, 0,
return;
thể mở file %s\n", SEEK_END);
filename); }
long fileSize =
return 0; ftell(file); char line[256];
} int numElements = while (fgets(line,
fileSize / sizeof(int); sizeof(line), file)) {
printf("%s",
int number;
line);
if (index < 0 ||
int sum = 0;
index >=
numElements) {
}
while fclose(file);
(fread(&number,
return -8080;
sizeof(int), 1, file)) { fclose(file);
}
if (number < 0) }
{
void
sum += fseek(file, index * ShowAccountNumber(
number; sizeof(int), const char* filename)
SEEK_SET); {
}
FILE* file =
}
fopen(filename, "r");
int value;
if (file == NULL) {
fread(&value,
fclose(file);
sizeof(int), 1, file); printf("Không
return sum; thể mở file %s\n",
filename);
}
fclose(file);
return;
int
FileIndexArrBi(const }
char* filename, int return value;
index) {
}
char line[256]; printf("Error!
Could not open file\
int
n");
accountNumber; //
Biến lưu số tài khoản exit(1);
char }
fullName[100];
// CODE HERE
float balance;
int so;
while(fscanf(fp,
// Đọc từng dòng "%d", &so) == 1){
dữ liệu
printf("%d ", so);
while (fgets(line,
}
sizeof(line), file)) {
fclose(fp);
// Tách thông tin
từ dòng printf("\n");
sscanf(line, "%d
%99[^\n] %f",
&accountNumber, }
fullName, &balance);
printf("%d\n",
accountNumber);