-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
269 additions
and
25 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
6 a | ||
6 b | ||
6 c | ||
6 d | ||
6 f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
random<-read.table("random.txt") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
5000 random no 10 0.042600 0.002000 0.004000 | ||
10000 random no 10 0.164000 0.004500 0.007000 | ||
15000 random no 10 0.366400 0.006000 0.011000 | ||
20000 random no 10 0.650100 0.008100 0.014900 | ||
25000 random no 10 1.012600 0.010000 0.019000 | ||
30000 random no 10 1.454600 0.011200 0.022600 | ||
35000 random no 10 2.197333 0.013000 0.026200 | ||
40000 random no 10 2.583800 0.015400 0.030400 | ||
45000 random no 10 3.263900 0.017000 0.034400 | ||
50000 random no 10 4.031900 0.019100 0.038400 | ||
55000 random no 10 4.871000 0.021100 0.042300 | ||
60000 random no 10 5.798200 0.023700 0.046600 | ||
65000 random no 10 6.801400 0.024600 0.050900 | ||
70000 random no 10 7.887700 0.026200 0.055400 | ||
75000 random no 10 11.313875 0.028800 0.059200 | ||
80000 random no 10 10.299800 0.030200 0.063300 | ||
85000 random no 10 11.625600 0.032100 0.067200 | ||
90000 random no 10 13.026700 0.034200 0.071500 | ||
95000 random no 10 14.535200 0.036300 0.077200 | ||
100000 random no 10 17.866556 0.038500 0.083000 | ||
105000 random no 10 17.724400 0.040300 0.085200 | ||
110000 random no 10 19.456700 0.042200 0.090500 | ||
115000 random no 10 23.640222 0.044100 0.094900 | ||
120000 random no 10 23.135700 0.047200 0.099800 | ||
125000 random no 10 25.100200 0.047500 0.104200 | ||
130000 random no 10 27.146900 0.051300 0.109800 | ||
135000 random no 10 29.282200 0.052500 0.068200 | ||
140000 random no 10 34.989444 0.054400 0.072400 | ||
145000 random no 10 33.767600 0.057000 0.074200 | ||
150000 random no 10 36.142500 0.059800 0.075800 | ||
155000 random no 10 38.570900 0.060300 0.078100 | ||
160000 random no 10 41.132500 0.062900 0.081800 | ||
165000 random no 10 48.604444 0.064300 0.084000 | ||
170000 random no 10 46.418400 0.068500 0.086400 | ||
175000 random no 10 54.690556 0.068700 0.089700 | ||
180000 random no 10 52.061900 0.070600 0.093000 | ||
185000 random no 10 78.566429 0.072600 0.094500 | ||
190000 random no 10 58.018700 0.074500 0.097900 | ||
195000 random no 10 61.282444 0.077400 0.100000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
6 a | ||
8 asi | ||
6 b | ||
1 asd | ||
9 asjf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
9 asjf | ||
1 asd | ||
6 a | ||
8 asi | ||
6 b | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Input Initial Has Number Avg Time Avg Time Avg Time | ||
size Order Dup. of runs of sortA of sortB for sort | ||
4000 random no 10 0.032111 0.002000 0.003100 | ||
4000 sorted no 10 0.027500 0.026900 0.002300 | ||
4000 reverse no 10 0.026800 0.025500 0.002000 | ||
8000 random no 10 0.106500 0.003600 0.006000 | ||
8000 sorted no 10 0.106200 0.102400 0.003400 | ||
8000 reverse no 10 0.100600 0.097100 0.004000 | ||
16000 random no 10 4.161000 0.006300 0.012000 | ||
16000 sorted no 10 0.461222 0.404100 0.006000 | ||
16000 reverse no 10 0.496875 0.383800 0.006600 | ||
32000 random no 10 1.663100 0.012200 0.024200 | ||
32000 sorted no 10 1.838556 1.606200 0.012100 | ||
32000 reverse no 10 3.933500 1.525600 0.012600 | ||
64000 random no 10 6.612600 0.024500 0.050200 | ||
64000 sorted no 10 7.318222 6.396800 0.024000 | ||
64000 reverse no 10 6.977000 6.075900 0.025000 | ||
128000 random no 10 26.341600 0.049400 0.107800 | ||
128000 sorted no 10 26.330100 25.594400 0.050000 | ||
128000 reverse no 10 25.071800 24.260300 0.052100 | ||
256000 random no 10 105.318200 0.101900 0.135500 | ||
256000 sorted no 10 105.311700 91.855900 0.076500 | ||
256000 reverse no 10 104.606556 87.112700 0.066100 | ||
512000 random no 10 420.875700 0.223000 0.190900 | ||
512000 sorted no 10 422.825000 230.812300 0.090100 | ||
512000 reverse no 10 400.441800 219.189100 0.093400 | ||
1024000 random no 10 0.000000 0.000000 0.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Queue.c ... list implementation of a queue | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <assert.h> | ||
#include "Queue.h" | ||
|
||
typedef struct QueueNode *Link; | ||
|
||
struct QueueNode { | ||
Item item; | ||
Link next; | ||
}; | ||
|
||
struct QueueRep { | ||
Link head; | ||
Link tail; | ||
int size; | ||
}; | ||
|
||
// private function for creating list nodes | ||
static Link createNode(Item item) | ||
{ | ||
Link n = malloc(sizeof(struct QueueNode)); | ||
assert(n != NULL); | ||
n->item = item; | ||
n->next = NULL; | ||
return n; | ||
} | ||
|
||
// create an initially empty Queue | ||
Queue createQueue(void) | ||
{ | ||
Queue q = malloc(sizeof(struct QueueRep)); | ||
assert(q != NULL); | ||
q->head = NULL; | ||
q->tail = NULL; | ||
q->size = 0; | ||
return q; | ||
} | ||
|
||
// free all memory used by the Queue | ||
void dropQueue(Queue q) | ||
{ | ||
Link curr; | ||
Link next; | ||
assert(q != NULL); | ||
curr = q->head; | ||
while (curr != NULL) { | ||
next = curr->next; | ||
curr = next; | ||
} | ||
free(q); | ||
} | ||
|
||
|
||
// add new Item to the tail of the Queue | ||
void enterQueue (Queue q, Item it) | ||
{ | ||
assert(q != NULL); | ||
Link n = createNode(it); | ||
if (q->head == NULL) { | ||
q->head = n; | ||
} | ||
q->size++; | ||
if (q->tail!= NULL) { | ||
q->tail->next = n; | ||
} | ||
q->tail = n; | ||
} | ||
|
||
// remove Item from head of Queue; return it | ||
Item leaveQueue (Queue q) | ||
{ | ||
assert(q != NULL); | ||
Item it = q->head->item; | ||
Link delNode = q->head; | ||
q->head = q->head->next; | ||
free(delNode); | ||
q->size--; | ||
return it; | ||
} | ||
|
||
// return count of Items in Queue | ||
int queueLength(Queue q) | ||
{ | ||
assert(q != NULL); | ||
return q->size; | ||
} | ||
|
||
// display Queue as list of 2-digit numbers | ||
void showQueue(Queue q) | ||
{ | ||
printf("H"); | ||
Link curr; | ||
curr = q->head; | ||
while (curr != NULL) { | ||
printf(" %02d", curr->item); | ||
curr= curr->next; | ||
} | ||
printf(" T\n"); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Simple program to test a sorting function | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define N 10 | ||
|
||
void sort(int [], int); | ||
void show(char *, int [], int); | ||
|
||
int main(void) | ||
{ | ||
int i, j, a[N]; | ||
|
||
srand(0); | ||
|
||
for (j = 1; j <= 5; j++) { | ||
// initialise array (pseudo-randomly) | ||
for (i = 0; i < N; i++) { | ||
a[i] = rand()%100; | ||
} | ||
|
||
// display, sort, then re-display | ||
printf("Test #%d\n",j); | ||
show("Sorting", a, N); | ||
sort(a, N); | ||
show("Sorted ", a, N); | ||
} | ||
return 0; | ||
} | ||
|
||
// sort array using bubble sort | ||
void sort(int a[], int n) | ||
{ | ||
int i, j, nswaps; | ||
for (i = 0; i < n; i++) { | ||
nswaps = 0; | ||
for (j = n; j > i; j--) { | ||
if (a[j] < a[j-1]) { | ||
int tmp; | ||
tmp = a[j]; | ||
a[j] = a[j-1]; | ||
a[j-1] = tmp; | ||
nswaps++; | ||
} | ||
} | ||
if (nswaps == 0) break; | ||
} | ||
} | ||
|
||
// display array, preceded by label | ||
void show(char *label, int a[], int n) | ||
{ | ||
int i; | ||
printf("%s:", label); | ||
for (i = 0; i < n; i++) { | ||
printf(" %02d", a[i]); | ||
} | ||
printf("\n"); | ||
} |
Binary file not shown.