| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12582 | Function Pointer Practice |
|
| 12594 | Implement Linked List |
|
| 13082 | Merge sorted lists |
|
Description
This is the practice for function pointer, you are be required to finish a task execulator using function pointer.
Given the below struct
typedef struct{
void (*func)(void *);
void *argument;
}Task;
typedef struct{
int* arr;
int lower;
int upper;
}Data;
typedef struct{
Task **tasks;
int size;
}Task_List;
and you need to implement 5 functions to pass this practice.
func1 : void job1(void* argument); // reverse
func2 : void job2(void* argument); // minus
func3 : void job3(void* argument); // double
func4 : void initTask(Task* task, void(*func)(void*),void* argument);
func5 : void executeTasks(Task_List *task_list);
For this problem, we will give you a global array and you need to modify the value in global array with different job using function pointer
Take two simple cases for example:
case 1 : when user input lower = 0, upper = 5 and method = 0 (job1) for an array A = {1,2,3,4,5,6,7}
output: 6, 5, 4, 3, 2, 1, 7
case 2: when user input lower = 2, upper = 4 and method = 1 (job2) for an array A = {1,2,3,4,5,6,7}
output: 1, 2, -3, -4, -5, 6, 7
case 3: when user input lower = 0, upper = 0 and method = 2 (job3) for an array A = {1,2,3,4,5,6,7}
output: 2, 2, 3, 4, 5, 6, 7
main.c
function.h
Input
T
Mi Li Ui
...
T: the number of task (2 < T < 100)
Mi: the type of job (Mi = {0, 1, 2})
Li: the lower bound of the array (0 <= Li < 25)
Ui: the upper bound of the array (Li <= Ui < 25)
Output
Output the global array after finishing all tasks.
Sample Input Download
Sample Output Download
Partial Judge Code
12582.cPartial Judge Header
12582.hTags
Discuss
Description
Given a link list structure named Node.
typedef struct _Node {
int data;
struct _Node *next;
} Node;
In this problem, you need to implement five operation for the linked list.
func1: Node* createList(int *a, int size);
func2: void push_front(Node** head, int val);
func3: Node* copyList(Node* head);
func4: void deleteElementByIdx(Node** head, int idx);
func5: void SwapElementByIdx(Node** head, int idx1, int idx2);
func1: using an array to build the link list
func2: append the input value to the first element in the linked list
ex: origin linked list : [0, 1, 2, 3], when call the function push_front(&head, 5). the final linked list will be [5 ,0 ,1, 2, 3]
func3: copy the original link list (not directly to assign it)
func4: delete the element by its index (begin from 0)
ex: origin linked list : [0, 1, 2, 3], when call the function deleteElementByIdx(&head, 0). the final linked list will be [1,2,3]
note that: if the idx out of range. you should ignore the delete operation
func5: swap the element in linked list by given idx1 and idx2 (both begin from 0)
ex: origin linked list: [0, 1, 2, 3], when call the function SwapElementByIdx(&head, 0, 3). the final linked list will be [3, 1, 2, 0]
note that: if the idx1 or idx2 out of range, you should ignore the swap operation
Note: We guarantee that function 1, 3~5 will not operate on an empty list.
Input
T M
S1 .. SM
t1_command
...
tT_command
T: the number of command ( 0 <= T < 200)
M: the number of initial linked size (0 <= M <= 2000)
Si: the value of the initial array (0 <= Si <= 1000)
ti_command: the command description
(0: push_front, 1: clone, 2: delete, 3: swap)
Hint:
testcase1 : contain only createList operation
testcase2: contain only push_front operation
testcase3: contain createList , push_front, copyList operation
testcase4: contain createList , push_front , copyList operation, deleteElementByIdx
testcase5: contain all operation
Output
Output the element in linked list whenever the operation be called.
Sample Input Download
Sample Output Download
Partial Judge Code
12594.cPartial Judge Header
12594.hTags
Discuss
Description
This is a partial judge problem.
Given two sorted linked lists which length are N and M respectively, you need to merge them into one sorted list and delete the duplicated numbers.
function.h
typedef struct _Node {
int data;
struct _Node *next;
} Node;
Node* Merge_lists(Node*, Node*);
You only need to implement the Merge_lists(Node*, Node*) function which take two sorted linked list as input.
Input
First line contains two integers which denote the number of the integers of two sorted lists. (1 <= N.M <= 10, 1 <= each integer <= 30)
Second line contains N integers which denote the first given sorted list.
Third line contains M integers which denote the second given sorted list.
Output
One merged sorted linked list result.