IM TRYING TO COMPILE THE SOURCE CODE but its giving me errors:
1 2 3 4 5 6
1
1> permute_append.cpp
1>c:\users\krrish\documents\visual studio 2010\projects\krishneelcad5430cisp40013f\krishneelcad5430cisp40013f\permute_append.cpp(78): fatal error C1075: end of file found before the left brace '{' at 'c:\users\krrish\documents\visual studio 2010\projects\krishneelcad5430cisp40013f\krishneelcad5430cisp40013f\linked_list.template(129)' was matched
1> main.cpp
1>c:\users\krrish\documents\visual studio 2010\projects\krishneelcad5430cisp40013f\krishneelcad5430cisp40013f\main.cpp(15): fatal error C1075: end of file found before the left brace '{' at 'c:\users\krrish\documents\visual studio 2010\projects\krishneelcad5430cisp40013f\krishneelcad5430cisp40013f\linked_list.template(129)' was matched
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
//file: permute_append.cpp//
#include <cstdlib> // Provides size_t // included in permute_append.h
#include <sstream>
#include <string> //provides string type //included in permute_append.h
#include "permute_append.h"
usingnamespace std;
namespace CISP430_A5
{
/*CONSTRUCTORS, DECONSTRUCTOR*/
permute_append::permute_append() {
firstString = "x"; // x is just a default value
secondString = "x"; // x is just a default value
total = 0;
}
permute_append::permute_append(constchar* first, constchar* second) {
firstString = first;
secondString = second;
total = 1; // at least one permutation
for (int i=firstString.length(); i>0; --i) { // number of permutations is equal to factorial of the number of characters in firstString
total *= i;
}
/*Turn string into linked list of chars*/
for (int i=0; i<firstString.length(); ++i) {
permute_me.add(firstString[i]);
}
}
permute_append::permute_append(const permute_append &source) {
firstString = source.firstString;
secondString = source.secondString;
total = source.total;
permute_me = source.permute_me;
result_list = source.result_list;
}
permute_append::~permute_append() {
total = 0;
firstString = "";
secondString = "";
/*so I guess we don't need to delete the linked_list object manually*/
// delete permute_me;
// delete result_list;
}
linked_list<string> permute_append::permute(linked_list<char> charList) { // permute the characters in the array (n items, n at a time)
/*Returns a linked_list of strings, each string a permutation of the chars in charList.*/
static linked_list<string> perms; static linked_list<char> usedChars;
linked_list<char> character;
for (int i = 0; i < charList.size(); ++i) {
character = list_splice(charList, i, 1); //??? How do we pass charList to list_splice so list_splice modifies charList directly? Answer: just like I did.
usedChars.add( character.get(0) );
if (charList.size() == 0) perms.add( charList_join("", usedChars) ); //??? Is charList_join() working? I believe so.
permute(charList);
list_splice( charList, i, 0, character.get(0) );
list_pop( usedChars );
}
return perms;
}
string permute_append::do_it() {
// appends secondString to each permutation of firstString and stores each result in result_list
linked_list<string> perms( permute(permute_me) ); // ??? How do you point to the returned linked_list properly?
// string result = "";
for (size_t i=0; i<perms.size(); ++i) {
result_list.add(perms.get(i) + secondString);
}
}
string permute_append::do_it(constchar* first, constchar* second) {
// set firstString and secondString then appends secondString to each permutation of firstString and stores each result in result_list
firstString = first; secondString = second;
do_it();
}
string permute_append::get(size_t position) { // get a result
/*Get the item at position position from result_list */
return result_list.get(position);
}
}
I am guessing there is a syntax error in your linked_list.h where you are not closing a code block correctly.
Also, it seems that linked_list.h doesn't have any include guards as both permute_append.cpp and main.cpp are giving you the error.
what do you mean by it seems that linked_list.h doesn't have any include guards
can you show how to include guards on it or did you mean declaration on those two files