Project 4 main backup

Project 4 main backup - main.cpp 5/4/09 11:37 AM #include...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 1 of 6 main.cpp 5/4/09 11:37 AM #include <iostream> #include <string> #include <cassert> using namespace std; int tally(const string a[], int n, string target) { int count = 0; if (n < 0) return -1; for (int i = 0; i < n; i++) { if (a[i] == target) count++; } return count; } int findFirst(const string a[], int n, string target) { int position = 0; for (position; position <= n; position++) { if (a[position] == target) { break; } if (position == n) return -1; } return position; } int positionOfMin(const string a[], int n) //CHECK ME: EMPTY STRING THING { int pos = 0; for (int j = 0; j < n; j++) { if (a[pos] <= a[j]) { } if (a[pos] > a[j]) { pos = j; j = 0; } } return pos;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Page 2 of 6 main.cpp 5/4/09 11:37 AM } int moveToEnd(string a[], int n, int pos) //notice it's not const string a[] { int opos = pos; //original position string end = a[pos]; //string being moved to the end for (int i = opos; i <= (n); i++) { if (i < n-1) a[i] = a[i+1]; if (i == n-1) a[i] = end; if (i == n) break; if (n < 0 || pos >= n) return -1; } return pos; } int moveToBeginning(string a[], int n, int pos) { int opos = pos; //original position string beg = a[pos]; //string being moved to the beginning for (int i = opos; i >= 0; i--) { if (i > 0) a[i] = a[i-1]; if (i == 0) a[i] = beg; if (n < 0 || pos >= n) return -1; } return pos; } int disagree(const string a1[], int n1, const string a2[], int n2) { int pos1 = 0; int pos2 = 0;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 6

Project 4 main backup - main.cpp 5/4/09 11:37 AM #include...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online