-
-
A simple linked-list, whose elements are registers composed of a 32-bit unsigned integer, representing a student number, and a string, used to store the student name.
-More...
-
#include <stdio.h>
-#include <stdint.h>
-
-
Go to the source code of this file.
-
- |
-SllNode * | sllDestroy (SllNode *list) |
- | Delete all registers in the list and initialize it.
|
- |
-void | sllPrint (SllNode *list, FILE *fout) |
- | Print the list's registers in ascending order of the nmec field.
|
- |
-SllNode * | sllLoad (SllNode *list, FILE *fin, bool *ok) |
- | Fill list with contents of given file.
|
- |
-SllNode * | sllInsert (SllNode *list, uint32_t nmec, const char *name) |
- | Insert a new register in the list.
|
- |
-SllNode * | sllRemove (SllNode *list, uint32_t nmec) |
- | Remove a register from the list.
|
- |
-const char * | sllGetName (SllNode *list, uint32_t nmec) |
- | Get the name of a student given its nmec.
|
- |
-bool | sllExists (SllNode *list, uint32_t nmec) |
- | Check the existence of a register by nmec.
|
- |
-
-
-
A simple linked-list, whose elements are registers composed of a 32-bit unsigned integer, representing a student number, and a string, used to store the student name.
-
The following operations are defined:
-- insertion of a register
-- search for a name by number
-- removal of a register
-- destruction of the list
-- print the list contents
-- load list from file
-
-
- Authors
- (2024) Artur Pereira <artur at ua.pt>
--
-(2024) Miguel Oliveira e Silva <mos at ua.pt>
-
-
-
◆ sllDestroy()
-
-
-
-
-
Delete all registers in the list and initialize it.
-
- Parameters
-
-
- [in] | list | Pointer to the head of the list to be processed |
-
-
-
-
- Returns
- The head of the list after processing
-
-
-
-
-
◆ sllPrint()
-
-
-
-
-
- void sllPrint |
- ( |
- SllNode * | list, |
-
-
- |
- |
- FILE * | fout ) |
-
-
-
-
-
Print the list's registers in ascending order of the nmec
field.
-
- Parameters
-
-
- [in] | list | Pointer to the head of the list to be processed |
- [in] | fout | stream where printing should be sent to |
-
-
-
-
-
-
-
-
◆ sllLoad()
-
-
-
-
-
- SllNode * sllLoad |
- ( |
- SllNode * | list, |
-
-
- |
- |
- FILE * | fin, |
-
-
- |
- |
- bool * | ok ) |
-
-
-
-
-
Fill list with contents of given file.
-
The file is just a two-columns table, using a semi-colon as field separator, containing a name and a number. The name can be composed of several words separated by single spaces.
- Parameters
-
-
- [in] | list | Pointer to the head of the list to be processed |
- [in] | fin | stream of the file to read from |
- [out] | ok | indication of a successful load |
-
-
-
-
- Precondition
- fin != NULL
-
- Returns
- The head of the list after processing
-
-
-
-
-
◆ sllInsert()
-
-
-
-
-
- SllNode * sllInsert |
- ( |
- SllNode * | list, |
-
-
- |
- |
- uint32_t | nmec, |
-
-
- |
- |
- const char * | name ) |
-
-
-
-
-
Insert a new register in the list.
-
-- The list should be kept in ascending order of the
nmec
field
-- A dynamic duplication of the string pointed to by
name
should be done - Parameters
-
-
- [in] | list | Pointer to the head of the list to be processed |
- [in] | nmec | The student's number |
- [in] | name | The student's name |
-
-
-
-- Precondition
- name != NULL && name[0] != '\0'
--
-!sllExists(list, nmec)
-- Returns
- The head of the list after processing
-
-
-
-
-
-
-
◆ sllRemove()
-
-
-
-
-
- SllNode * sllRemove |
- ( |
- SllNode * | list, |
-
-
- |
- |
- uint32_t | nmec ) |
-
-
-
-
-
Remove a register from the list.
-
-- The list must be traversed in order to find the register to be removed
-- Recall that the list is sorted in nmec ascending order, in order to improve the algorithm used
- Parameters
-
-
- [in] | list | Pointer to the head of the list to be processed |
- [in] | nmec | The nmec associated to the register to be removed |
-
-
-
-- Precondition
- list != NULL
--
-sllExists(list, nmec)
-- Returns
- The head of the list after processing
-
-
-
-
-
-
-
◆ sllGetName()
-
-
-
-
-
- const char * sllGetName |
- ( |
- SllNode * | list, |
-
-
- |
- |
- uint32_t | nmec ) |
-
-
-
-
-
Get the name of a student given its nmec.
-
-- The list must be traversed in order to find the given nmec and the corresponding name should be returned.
-- Recall that the list is sorted in nmec ascending order, in order to improve the algorithm used
- Parameters
-
-
- [in] | list | Pointer to the head of the list to be processed |
- [in] | nmec | The nmec to be searched |
-
-
-
-- Precondition
- list != NULL
--
-sllExists(list, nmec)
-- Returns
- the corresponding name
-
-
-
-
-
-
-
◆ sllExists()
-
-
-
-
-
- bool sllExists |
- ( |
- SllNode * | list, |
-
-
- |
- |
- uint32_t | nmec ) |
-
-
-
-
-
Check the existence of a register by nmec.
-
- Parameters
-
-
- [in] | list | Pointer to the head of the list to be processed |
- [in] | nmec | The nmec associated to the register to be removed |
-
-
-
-
- Returns
- true if it exists and false otherwise
-
-
-
-