-
Notifications
You must be signed in to change notification settings - Fork 0
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
38 changed files
with
2,456 additions
and
6 deletions.
There are no files selected for viewing
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
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 @@ | ||
# This code depends on make tool being used | ||
DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES} ${TESTOBJECTFILES})) | ||
ifneq (${DEPFILES},) | ||
include ${DEPFILES} | ||
endif |
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,128 @@ | ||
# | ||
# There exist several targets which are by default empty and which can be | ||
# used for execution of your targets. These targets are usually executed | ||
# before and after some main targets. They are: | ||
# | ||
# .build-pre: called before 'build' target | ||
# .build-post: called after 'build' target | ||
# .clean-pre: called before 'clean' target | ||
# .clean-post: called after 'clean' target | ||
# .clobber-pre: called before 'clobber' target | ||
# .clobber-post: called after 'clobber' target | ||
# .all-pre: called before 'all' target | ||
# .all-post: called after 'all' target | ||
# .help-pre: called before 'help' target | ||
# .help-post: called after 'help' target | ||
# | ||
# Targets beginning with '.' are not intended to be called on their own. | ||
# | ||
# Main targets can be executed directly, and they are: | ||
# | ||
# build build a specific configuration | ||
# clean remove built files from a configuration | ||
# clobber remove all built files | ||
# all build all configurations | ||
# help print help mesage | ||
# | ||
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and | ||
# .help-impl are implemented in nbproject/makefile-impl.mk. | ||
# | ||
# Available make variables: | ||
# | ||
# CND_BASEDIR base directory for relative paths | ||
# CND_DISTDIR default top distribution directory (build artifacts) | ||
# CND_BUILDDIR default top build directory (object files, ...) | ||
# CONF name of current configuration | ||
# CND_PLATFORM_${CONF} platform name (current configuration) | ||
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) | ||
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) | ||
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) | ||
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration) | ||
# CND_PACKAGE_NAME_${CONF} name of package (current configuration) | ||
# CND_PACKAGE_PATH_${CONF} path to package (current configuration) | ||
# | ||
# NOCDDL | ||
|
||
|
||
# Environment | ||
MKDIR=mkdir | ||
CP=cp | ||
CCADMIN=CCadmin | ||
|
||
|
||
# build | ||
build: .build-post | ||
|
||
.build-pre: | ||
# Add your pre 'build' code here... | ||
|
||
.build-post: .build-impl | ||
# Add your post 'build' code here... | ||
|
||
|
||
# clean | ||
clean: .clean-post | ||
|
||
.clean-pre: | ||
# Add your pre 'clean' code here... | ||
|
||
.clean-post: .clean-impl | ||
# Add your post 'clean' code here... | ||
|
||
|
||
# clobber | ||
clobber: .clobber-post | ||
|
||
.clobber-pre: | ||
# Add your pre 'clobber' code here... | ||
|
||
.clobber-post: .clobber-impl | ||
# Add your post 'clobber' code here... | ||
|
||
|
||
# all | ||
all: .all-post | ||
|
||
.all-pre: | ||
# Add your pre 'all' code here... | ||
|
||
.all-post: .all-impl | ||
# Add your post 'all' code here... | ||
|
||
|
||
# build tests | ||
build-tests: .build-tests-post | ||
|
||
.build-tests-pre: | ||
# Add your pre 'build-tests' code here... | ||
|
||
.build-tests-post: .build-tests-impl | ||
# Add your post 'build-tests' code here... | ||
|
||
|
||
# run tests | ||
test: .test-post | ||
|
||
.test-pre: build-tests | ||
# Add your pre 'test' code here... | ||
|
||
.test-post: .test-impl | ||
# Add your post 'test' code here... | ||
|
||
|
||
# help | ||
help: .help-post | ||
|
||
.help-pre: | ||
# Add your pre 'help' code here... | ||
|
||
.help-post: .help-impl | ||
# Add your post 'help' code here... | ||
|
||
|
||
|
||
# include project implementation makefile | ||
include nbproject/Makefile-impl.mk | ||
|
||
# include project make variables | ||
include nbproject/Makefile-variables.mk |
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,166 @@ | ||
/* | ||
* File: main.cpp | ||
* Author: Dr. Mark E. Lehr | ||
*/ | ||
|
||
//Libraries | ||
#include <cstdlib>//Random number seed | ||
#include <ctime>//Set the seed | ||
#include <iostream> | ||
#include <set>//I/O | ||
using namespace std; | ||
|
||
//No Global Constants | ||
|
||
//Function Prototypes | ||
int *fillAry(int,int); | ||
void prntAry(int *,int,int); | ||
void prntMod(int *); | ||
void swap(int *,int *); | ||
void minPos(int *,int,int); | ||
void mrkSort(int *,int); | ||
int *mode(const int *,int); | ||
int *copy(const int *,int); | ||
|
||
//Execution begins here | ||
int main(int argc, char*argv[]) { | ||
//Declare variables and fill | ||
int arySize=15; | ||
int modNum=10; | ||
int *ary=fillAry(arySize,modNum); | ||
|
||
//Print the initial array | ||
prntAry(ary,arySize,10); | ||
|
||
//Calculate the mode array | ||
int *modeAry=mode(ary,arySize); | ||
|
||
//Print the modal information of the array | ||
prntMod(modeAry); | ||
|
||
//Delete allocated memory | ||
delete []ary; | ||
delete []modeAry; | ||
|
||
//Exit stage right | ||
return 0; | ||
} | ||
|
||
int *copy(const int *a,int n){ | ||
//Declare and allocate an array | ||
//that is a c | ||
int *b=new int[n]; | ||
//Fill | ||
for(int i=0;i<n;i++){ | ||
b[i]=a[i]; | ||
} | ||
//Return the copy | ||
return b; | ||
} | ||
|
||
int *mode(const int *array,int arySize){ | ||
//Copy the array | ||
int *ary=copy(array,arySize); | ||
//Sort the ary | ||
mrkSort(ary,arySize); | ||
//Sort the copy | ||
set<int> mySet; | ||
|
||
//Find the max Freq | ||
int count=0,maxFreq=0; | ||
for(int i=0;i<arySize-1;i++){ | ||
if(ary[i]==ary[i+1]){ | ||
count++; | ||
if(maxFreq<count) | ||
maxFreq=count; | ||
}else{ | ||
count=0; | ||
} | ||
} | ||
//Find the number of modes | ||
count=0; | ||
for(int i=0;i<arySize-1;i++){ | ||
if(ary[i]==ary[i+1]){ | ||
count++; | ||
if(maxFreq==count) | ||
mySet.insert(ary[i]); | ||
}else{ | ||
count=0; | ||
} | ||
} | ||
//Allocate the mode array | ||
int *modeAry=new int[mySet.size() + 2]; | ||
//Fill the mode array | ||
modeAry[0]= mySet.size(); | ||
modeAry[1]=maxFreq+1; | ||
count=0; | ||
int indx=2; | ||
for(set<int>::iterator itr = mySet.begin(); itr != mySet.end(); itr++){ | ||
modeAry[indx++] = *itr; | ||
} | ||
|
||
//Delete the allocated copy and return | ||
delete []ary; | ||
return modeAry; | ||
} | ||
|
||
void prntMod(int *ary){ | ||
cout<<endl; | ||
cout<<"The number of modes = "<< | ||
ary[0]<<endl; | ||
cout<<"The max Frequency = "<< | ||
ary[1]<<endl; | ||
if(ary[0]==0){ | ||
cout<<"The mode set = {null}"<<endl; | ||
return; | ||
} | ||
cout<<"The mode set = {"; | ||
for(int i=2;i<ary[0]+1;i++){ | ||
cout<<ary[i]<<","; | ||
} | ||
cout<<ary[ary[0]+1]<<"}"<<endl; | ||
} | ||
|
||
void mrkSort(int *array,int n){ | ||
for(int i=0;i<n-1;i++){ | ||
minPos(array,n,i); | ||
} | ||
} | ||
|
||
void minPos(int *array,int n,int pos){ | ||
for(int i=pos+1;i<n;i++){ | ||
if(*(array+pos)>*(array+i)) | ||
swap(array+pos,array+i); | ||
} | ||
} | ||
|
||
void swap(int *a,int *b){ | ||
//Swap in place | ||
*a=*a^*b; | ||
*b=*a^*b; | ||
*a=*a^*b; | ||
} | ||
|
||
void prntAry(int *array,int n,int perLine){ | ||
//Output the array | ||
cout<<endl; | ||
for(int i=0;i<n;i++){ | ||
cout<<*(array+i)<<" "; | ||
if(i%perLine==(perLine-1))cout<<endl; | ||
} | ||
cout<<endl; | ||
} | ||
|
||
int *fillAry(int n, int modNum){ | ||
//Allocate memory | ||
int *array=new int[n]; | ||
|
||
//Fill the array with 2 digit numbers | ||
for(int i=0;i<n;i++){ | ||
*(array+i)=i%modNum; | ||
//*(array+i)=rand()%modNum; | ||
} | ||
|
||
//Exit function | ||
return array; | ||
} |
Oops, something went wrong.