Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
COMS327
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jake Feddersen
COMS327
Commits
6968723c
Commit
6968723c
authored
6 years ago
by
Jake Feddersen
Browse files
Options
Downloads
Patches
Plain Diff
Add notes from the past few days
parent
4498016f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
notes/2_15/insertion_sort
+0
-0
0 additions, 0 deletions
notes/2_15/insertion_sort
notes/2_15/insertion_sort.c
+98
-0
98 additions, 0 deletions
notes/2_15/insertion_sort.c
notes/2_18/macros.c
+23
-0
23 additions, 0 deletions
notes/2_18/macros.c
with
121 additions
and
0 deletions
notes/2_15/insertion_sort
0 → 100755
+
0
−
0
View file @
6968723c
File added
This diff is collapsed.
Click to expand it.
notes/2_15/insertion_sort.c
0 → 100644
+
98
−
0
View file @
6968723c
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
void
insertion_sort
(
int
*
a
,
int
n
)
{
int
i
,
j
,
t
;
for
(
i
=
1
;
i
<
n
;
i
++
)
{
for
(
t
=
a
[
i
],
j
=
i
-
1
;
j
>
-
1
&&
a
[
j
]
>
t
;
j
--
)
{
a
[
j
+
1
]
=
a
[
j
];
}
a
[
j
+
1
]
=
t
;
}
}
/**
* data - array to sort
* n - number of items in the array
* s - size of the data items
* comparator - pointer to function to compare the data
*/
void
generic_insertion_sort
(
void
*
data
,
int
n
,
size_t
s
,
int
(
*
compare
)(
const
void
*
,
const
void
*
))
{
int
i
,
j
;
void
*
t
;
char
*
a
;
// Not allowed to do pointer math, dereference, etc on data
// So assign the same address to a pointer we actually can work with
a
=
data
;
t
=
malloc
(
s
);
for
(
i
=
1
;
i
<
n
;
i
++
)
{
// t = a[i]
for
(
memcpy
(
t
,
a
+
(
i
*
s
),
s
),
j
=
i
-
1
;
j
>
-
1
&&
compare
(
a
+
(
j
*
s
),
t
)
>
0
;
j
--
)
{
// a[j + 1] = a[j];
memcpy
(
a
+
((
j
+
1
)
*
s
),
a
+
(
j
*
s
),
s
);
}
//a[j+1] = t;
memcpy
(
a
+
((
j
+
1
)
*
s
),
t
,
s
);
}
free
(
t
);
}
int
compare_ints
(
const
void
*
v1
,
const
void
*
v2
)
{
return
*
((
const
int
*
)
v2
)
-
*
((
const
int
*
)
v1
);
}
int
compare_chars
(
const
void
*
v1
,
const
void
*
v2
)
{
return
*
((
const
char
*
)
v2
)
-
*
((
const
char
*
)
v1
);
}
int
compare_strings
(
const
void
*
v1
,
const
void
*
v2
)
{
return
strcmp
(
*
(
const
char
**
)
v1
,
*
(
const
char
**
)
v2
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
a
[
10
]
=
{
10
,
93
,
8
,
7
,
6
,
25
,
43
,
3
,
2
,
1
};
int
i
;
char
c
[
10
]
=
"HelloCS327"
;
char
*
s
[
10
]
=
{
"one"
,
"two"
,
"three"
,
"four"
,
"five"
,
"six"
,
"seven"
,
"eight"
,
"nine"
,
"ten"
};
insertion_sort
(
a
,
sizeof
(
a
)
/
sizeof
(
a
[
0
]));
generic_insertion_sort
(
a
,
sizeof
(
a
)
/
sizeof
(
a
[
0
]),
sizeof
(
a
[
0
]),
compare_ints
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
printf
(
"%d
\n
"
,
a
[
i
]);
}
generic_insertion_sort
(
c
,
sizeof
(
c
)
/
sizeof
(
c
[
0
]),
sizeof
(
c
[
0
]),
compare_chars
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
printf
(
"%c
\n
"
,
c
[
i
]);
}
generic_insertion_sort
(
s
,
sizeof
(
s
)
/
sizeof
(
s
[
0
]),
sizeof
(
s
[
0
]),
compare_strings
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
printf
(
"%s
\n
"
,
s
[
i
]);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
notes/2_18/macros.c
0 → 100644
+
23
−
0
View file @
6968723c
//#include <stdio.h>
#define MAX_ROOMS 20
#define min(x, y) (x < y ? x : y)
#define max(x, y) ({ \
typeof (x) _x = x; \
typeof (y) _y = y; \
_x > _y ? _x : _y; \
})
int
main
(
int
argc
,
char
*
argv
[])
{
MAX_ROOMS
;
min
(
3
,
4
);
min
(
foo
(
x
),
bar
(
x
));
max
(
foo
(
x
),
bar
(
x
));
if
(
10
>
min
(
foo
(
x
),
bar
(
x
)))
{
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment