-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion3.c
More file actions
35 lines (28 loc) · 795 Bytes
/
Question3.c
File metadata and controls
35 lines (28 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>
#include "Questions.h"
// this is the very first question without hints in the comments. read the manual to develop your own algorithm
// Read Questions.h to understand the definition of Q3Struct
void efficient(const int source[], struct Q3Struct effVector[], int size)
{
int i;
int j=0;
for (i = 0; i < size; i++)
{
if (source[i] != 0)
{
//effVector[i] = {source[i], i};
effVector[j].pos = i;
effVector[j].val = source[i];
j++;
}
}
}
void reconstruct(int source[], int m, const struct Q3Struct effVector[], int n)
{
int i;
for (i = 0; i < n; i++)
{
source[effVector[i].pos] = effVector[i].val;
}
}