Created
May 5, 2018 02:40
-
-
Save magks/201e459300aa1af341a92b0207e4e27c to your computer and use it in GitHub Desktop.
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
#include "String.h" | |
struct ListNode | |
{ | |
char* info; | |
ListNode * next; | |
ListNode( char *newInfo, ListNode * newNext ) | |
: info(newInfo), next( newNext ) | |
{ | |
} | |
}; | |
String::String( const char * s ) | |
: head ( nullptr ) | |
{ | |
// head is null which is tight but i got a char * full of elements | |
head->next = stringToList( s ); | |
} | |
String::String( const String & s ) | |
{ | |
} | |
String String::operator = ( const String & s ) | |
{ | |
// r | |
} | |
char & String::operator [] ( int index ) | |
{ | |
if ( ! inBounds(index) ){ | |
cerr << "Error index "<< index << " out of bounds! " << endl; | |
} | |
} | |
int String::size() const | |
{ | |
return 1; | |
} | |
String String::reverse() const | |
{ | |
//make and return a new string | |
// Note: ask Dr. Klefstad why this is a mem leak: | |
// String rev(buf); | |
// reverse_cpy( rev.buf , buf ); | |
return *this; | |
} | |
int String::indexOf( const char c ) const | |
{ | |
//Question: Is c in the string? | |
// it must be found | |
//, we will arrive at an answer | |
// step by step | |
return 1; | |
} | |
bool String::operator == ( const String s ) const | |
{ | |
//return true if this.buf and s.buf are the same ascii sequence | |
return 0; | |
} | |
bool String::operator < ( const String s ) const | |
{ | |
// ret true if this buf loses in an ascii value contest | |
} | |
/// concatenates this and s to return result | |
String String::operator + ( const String s ) const | |
{ | |
String cat; | |
return cat; | |
} | |
/// concatenates s onto end of this string | |
String String::operator += ( const String s ) | |
{ | |
} | |
void String::print( ostream & out ) const | |
{ //notes recommend out << buf; | |
// out must flow each char of this string | |
// and no more | |
// precise freedom | |
} | |
void String::read( istream & in ) | |
{ | |
} | |
String::~String() | |
{ | |
} | |
bool String::inBounds( int i ) | |
{ | |
return i >= 0 && i < size(); | |
} | |
ListNode * stringToList( const char * s ) | |
{ | |
if ( *s == '\0' ) | |
return nullptr ; | |
ListNode nextChar( *s, stringToList( s+1 )); | |
return &nextChar; | |
} | |
String::ListNode * copy( const char * s) | |
{ | |
} | |
String::ListNode * reverse( const char * s) | |
{ | |
} | |
String::ListNode * append( const char * s) | |
{ | |
} | |
ListNode * find( const char * s) | |
{ | |
} | |
ListNode * compare( const char * s) | |
{ | |
} | |
ListNode * deleteList( const char * s) | |
{ | |
} | |
ostream & operator << ( ostream & out, String str ) | |
{ | |
return out; | |
} | |
istream & operator >> ( istream & in, String & str ) | |
{ | |
return in; | |
} | |
/* | |
bool String::operator != ( const String s ) | |
{ | |
//ret true if this.buf an s.buf are not the same ascii sequence | |
} | |
bool String::operator > ( const String s ) | |
{ | |
// ret true if this buf wins in an ascii value contest | |
} | |
bool String::operator <= ( const String s ) | |
{ | |
//ret true if this buf loses in ascii val contest or ties | |
} | |
bool String::operator >= ( const String s ) | |
{ | |
//ret true if this buf wins in ascii val contest or ties | |
} | |
*/ | |
// String.h file | |
#include <iostream> | |
using namespace std; | |
struct ListNode; | |
class String | |
{ | |
public: | |
explicit String( const char * s = ""); | |
String( const String & s ); | |
String operator = ( const String & s ); | |
char & operator [] ( int index ); | |
int size() const; | |
String reverse()const; // does not modify this String | |
int indexOf( const char c )const; | |
//int indexOf( const String pattern )const; | |
bool operator == ( const String s )const; | |
bool operator < ( const String s )const; | |
String operator + ( const String s ) const; | |
String operator += ( const String s ); | |
/* | |
bool operator != ( const String s ); | |
bool operator > ( const String s ); | |
bool operator <= ( const String s ); | |
bool operator >= ( const String s ); | |
*/ | |
/// concatenates this and s to return result | |
/// concatenates s onto end of this | |
void print( ostream & out )const; | |
void read( istream & in ); | |
//deletemechar * incr_size(); | |
~String(); | |
private: | |
bool inBounds( int i ); | |
//struct ListNode; | |
ListNode * head; | |
static ListNode * stringToList(const char *s); | |
static ListNode * copy( ListNode * L); | |
static ListNode * reverse( ListNode * L); | |
static ListNode * append( ListNode * L1, ListNode * L2); | |
static ListNode * find(char c,ListNode * L);//indexOf(char) | |
static int compare( ListNode * L1, ListNode * L2); //strcmp | |
static void deleteList( ListNode * L); //called 2 delete any list | |
static int length( ListNode * L); //O(N) so call rarely | |
}; | |
ostream & operator << ( ostream & out, String str ); | |
istream & operator >> ( istream & in, String & str ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment