-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kelly Manahan #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ | |
*/ | ||
void swap(int* a, int* b) | ||
{ | ||
|
||
int temp = *a; | ||
*a = *b; | ||
b = temp; | ||
} | ||
|
||
/* | ||
|
@@ -34,7 +36,12 @@ char *find_char(char *str, int c) | |
*/ | ||
void string_copy(char *x, char *y) | ||
{ | ||
|
||
while (*y != '\0') { | ||
*x = y; | ||
x++; | ||
y++; | ||
} | ||
*x ='\0'; | ||
} | ||
|
||
/* | ||
|
@@ -53,7 +60,7 @@ void string_copy(char *x, char *y) | |
*/ | ||
int string_compare(char *m, char *n) | ||
{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No code here for |
||
} | ||
|
||
/* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,35 @@ | |
*/ | ||
void quicksort(int *arr, int low, int high) | ||
{ | ||
int i, j, pivot, temp; | ||
|
||
if(low < high){ | ||
pivot=low; | ||
i = low; | ||
j = high; | ||
|
||
while(i<j) { | ||
while (arr[i] <= arr[pivot] && i < high) | ||
i++; | ||
while( arr[j] > arr[pivot]) | ||
j--; | ||
if(i<j) { | ||
temp=arr[i]; | ||
arr[i] = arr[j]; | ||
arr[j]=temp; | ||
} | ||
} | ||
|
||
temp = arr[pivot]; | ||
arr[pivot] = arr[j]; | ||
arr[j] = temp; | ||
quicksort(arr, low, j - 1); | ||
quicksort(arr, j + 1, high); | ||
} | ||
|
||
} | ||
|
||
#ifndef TESTING | ||
// #ifndef TESTING | ||
int main(void) | ||
{ | ||
int arr1[] = {100, 55, 4, 98, 10, 18, 90, 95, 43, 11, 47, 67, 89, 42, 49, 79}; | ||
|
@@ -35,4 +60,4 @@ int main(void) | |
|
||
return 0; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tested. works. great job! |
||
#endif | ||
// #endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
|
||
/* | ||
Given a character array s, return the number of characters | ||
held inside it. | ||
|
@@ -9,9 +10,15 @@ | |
*/ | ||
int string_length(char s[]) | ||
{ | ||
|
||
int len = 0; | ||
for(int i = 0; s[i] != '\0'; i++ ) | ||
{ | ||
len++; | ||
} | ||
return len; | ||
// return printf("%d", len); | ||
// return printf("%c", s[0]); | ||
} | ||
|
||
/* | ||
Write a function that reverses the order of string s and outputs | ||
the reversed string to the input array rv. The rv array will have | ||
|
@@ -20,7 +27,15 @@ int string_length(char s[]) | |
*/ | ||
char *reverse_string(char rv[], char s[]) | ||
{ | ||
|
||
int rvlen = string_length(s); | ||
int arr = 0; | ||
int i; | ||
for (i= (rvlen -1); i>=0; i--) { | ||
rv[arr] = s[i]; | ||
arr++; | ||
} | ||
rv[rvlen] ='\0'; | ||
return rv; | ||
} | ||
|
||
#ifndef TESTING | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks good. tested. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,13 @@ | |
Person should have the fields `name`, `age`, `height`, and `weight`. | ||
*/ | ||
typedef struct Person { | ||
|
||
char *name; | ||
int age; | ||
int height; | ||
int weight | ||
} Person; | ||
|
||
|
||
/* | ||
Creates an instance of the Person struct that receives all the relevant | ||
pieces of data associated with a Person instance. | ||
|
@@ -21,7 +25,13 @@ typedef struct Person { | |
*/ | ||
Person *createPerson(char *name, int age, int height, int weight) | ||
{ | ||
Person *p = malloc(sizeof(Person)); | ||
p->name = string_dup(name); | ||
p->age =age; | ||
p->height = height; | ||
p->weight = weight; | ||
|
||
return p; | ||
} | ||
|
||
/* | ||
|
@@ -30,7 +40,12 @@ Person *createPerson(char *name, int age, int height, int weight) | |
*/ | ||
void destroyPerson(Person *who) | ||
{ | ||
|
||
if (who != NULL) { | ||
if (who -> name !=NULL) { | ||
free(who -> name); | ||
} | ||
free(who); | ||
} | ||
} | ||
|
||
#ifndef TESTING | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tested. works! great work! |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but it would be better if the instructions for the program told what to do if it was divisible by 3 and divisible by 5...that way in the grand scheme of things....it's only looking for numbers that are divisible by 3 and 5...not 3, 5 and 15.