Differences

This shows you the differences between two versions of the page.

Link to this comparison view

driver.cpp [2014/10/26 01:52] (current)
Line 1: Line 1:
 +<​code>​
 +// Driver.cpp
 +// driver functions to test the MS Coding questions
 +// 
 +// Author : Madan Nain
 +// 
  
 +// ===== include'​s =====
 +#include <​iostream>​
 +#include "​duplicate.h"​
 +#include "​RemoveString.h"​
 +#include "​FindPosition.h"​
 +#include "​MergeSortedLists.h"​
 +
 +using namespace std;
 +
 +// ===== define'​s =====
 +#define TEST_MISC
 +
 +// ===== function prototypes'​s =====
 +int main(int argc, char **argv, char **envp);
 +void dumpArray(int ary[], int len);
 +void testmain(void);​
 +
 +// ===== globals =====
 +
 +// ===== main() =====
 +// driver function to test all functions for the 4 Coding questions
 +//
 +int main(int argc, char **argv, char **envp) {
 +#ifdef TEST_DUPLICATE
 + // MS Coding question 1
 + int ary[] = { 4, 1, 3, 2, 4};
 + const int N = 5;
 +
 + dumpArray(ary,​ N);
 + std::cout << "​Duplicate element is : " << duplicate(ary,​ N) << std::endl;
 +#endif
 +#ifdef TEST_REMOVESTRING
 + // MS Coding question 2
 + char hayStack[] = "This is is nice.";​
 + char removeStr[] = "​is";​
 + cout << "​Original String : " << hayStack << endl;
 + RemoveString(hayStack,​ removeStr);
 + cout << "After removing all occurences of " << removeStr << " : " << hayStack << endl;
 +#endif
 +#ifdef TEST_BINARYSEARCH
 + // MS Coding question 3
 + int findArray[] = { -100, -5, -1};
 + dumpArray(findArray,​ sizeof(findArray) / sizeof(int));​
 + int ndx = FindPosition(findArray,​ sizeof(findArray)/​sizeof(int),​ -1);
 + if (ndx >= 0) {
 + cout << "Found : Index : " << ndx << " Value : " << findArray[ndx] << endl;
 + } else 
 + cout << "Not found" << endl;
 +#endif
 +#ifdef TEST_MERGESORT
 + // MS Coding question 4
 +
 + Node *listA = NULL;
 + listA = addToList(listA,​ 10);
 + listA = addToList(listA,​ 7);
 + listA = addToList(listA,​ 2);
 + listA = addToList(listA,​ 7);
 + listA = addToList(listA,​ 4);
 + dumpList("​List A", listA);
 +
 + Node *listB = NULL;
 + listB = addToList(listB,​ 4);
 + listB = addToList(listB,​ 3);
 + listB = addToList(listB,​ 1);
 + listB = addToList(listB,​ 2);
 + dumpList("​List B", listB);
 +
 + Node *sortedList = MergeSortedLists(listA,​ listB);
 +
 + dumpList("​Merge Sorted",​ sortedList);​
 +#endif
 +
 +#ifdef TEST_MISC
 + testmain();​
 +#endif
 + return 0;
 +}
 +
 +// ===== dumpArray() =====
 +// support function to dump an int array
 +void dumpArray(int ary[], int len) {
 + for (int i=0; i<len; i++) {
 + cout << "​["​ << i << "​]="​ << ary[i];
 + if (i < len-1) cout << ",";​
 + }
 + cout << endl;
 +}
 +
 +</​code>​
driver.cpp.txt ยท Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0