Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
b-tree
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
norbert.dajnowski
b-tree
Commits
6074f0df
Commit
6074f0df
authored
Dec 04, 2019
by
norbert.dajnowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final Commit
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
0 deletions
+121
-0
b-tree.c
b-tree.c
+103
-0
pg03data.txt
pg03data.txt
+18
-0
No files found.
b-tree.c
0 → 100644
View file @
6074f0df
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAXCHAR 1000
FILE
*
file
;
char
data
[
MAXCHAR
];
struct
node
{
char
record
[
200
];
char
key
[
50
];
char
module
[
50
];
char
year
[
50
];
char
semester
[
50
];
struct
node
*
left
;
struct
node
*
right
;
};
struct
node
*
createNode
(
char
record
[
200
]){
struct
node
*
newNode
=
malloc
(
sizeof
(
struct
node
));
strcpy
(
newNode
->
record
,
record
);
char
*
token
=
strtok
(
record
,
","
);
strcpy
(
newNode
->
key
,
token
);
token
=
strtok
(
NULL
,
","
);
strcpy
(
newNode
->
module
,
token
);
token
=
strtok
(
NULL
,
","
);
strcpy
(
newNode
->
year
,
token
);
token
=
strtok
(
NULL
,
","
);
strcpy
(
newNode
->
semester
,
token
);
newNode
->
left
=
NULL
;
newNode
->
right
=
NULL
;
return
newNode
;
}
struct
node
*
input
(
struct
node
*
root
,
char
record
[
200
])
{
if
(
root
==
NULL
)
return
createNode
(
record
);
if
(
strcmp
(
record
,
root
->
record
)
<
0
){
root
->
left
=
input
(
root
->
left
,
record
);
}
else
if
(
strcmp
(
record
,
root
->
record
)
>
0
){
root
->
right
=
input
(
root
->
right
,
record
);
}
return
root
;
}
void
traverse_order
(
struct
node
*
root
){
if
(
root
==
NULL
)
return
;
traverse_order
(
root
->
left
);
printf
(
"%s (Left: "
,
root
->
key
);
if
(
root
->
left
!=
NULL
)
printf
(
"%s)"
,
root
->
left
->
key
);
else
printf
(
"NULL)"
);
if
(
root
->
right
!=
NULL
)
printf
(
" (Right: %s)
\n
"
,
root
->
right
->
key
);
else
printf
(
" (Right: NULL)
\n
"
);
fflush
(
stdout
);
fputs
(
root
->
record
,
file
);
traverse_order
(
root
->
right
);
}
int
main
()
{
char
*
filenameread
=
"pg03data.txt"
;
char
*
filenamewrite
=
"pg03sorted.txt"
;
int
counter
=
1
;
struct
node
*
root
=
NULL
;
file
=
fopen
(
filenameread
,
"r"
);
if
(
file
==
NULL
)
printf
(
"Could not open read file %s"
,
filenameread
);
while
(
fgets
(
data
,
MAXCHAR
,
file
)
!=
NULL
){
if
(
counter
==
1
){
root
=
input
(
root
,
data
);
counter
=
counter
+
1
;
}
else
input
(
root
,
data
);
}
fclose
(
file
);
file
=
fopen
(
filenamewrite
,
"w"
);
if
(
file
==
NULL
)
printf
(
"Could not open file to write to %s"
,
filenamewrite
);
traverse_order
(
root
);
fclose
(
file
);
return
0
;
}
\ No newline at end of file
pg03data.txt
0 → 100644
View file @
6074f0df
2103, Networking, Year 02, Semester 01
3109, Advanced Web Development, Year 03, Semester 02
1101, Programming 01, Year 01, Semester 01
2107, Mobile Programming, Year 02, Semester 02
1103, Computer Fundamentals, Year 01, Semester 01
3101, Major Project, Year 03, Semester 01
1105, Programming 02, Year 01, Semester 02
2108, Professional Project, Year 02, Semester 02
1106, Software Engineering, Year 01, Semester 02
2102, Databases, Year 02, Semester 01
3105, The Internet Of Things, Year 03, Semester 01
3107, Artificial Intelligence, Year 03, Semester 02
3108, Cybercrime Security, Year 03, Semester 02
1102, Mathematics, Year 01, Semester 01
1107, Technology In Context, Year 01, Semester 02
2101, Programmming 03, Year 02, Semester 01
2109, Philosophies of Technology, Year 02, Semester 02
3104, Human Computer Interaction, Year 03, Semester 01
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment