コード例 #1
0
ファイル: LinkedList.cpp プロジェクト: yida/CodingInterview
int main() {
  LinkedList list;
  list.insertHead(45);
  list.insertHead(23);
  list.print();
  list.insertTail(456);
  list.insertTail(234);
  list.insertTail(34);
  list.print();
  cout << list.remove(456) << endl;
  list.print();
  list.removeHead();
  list.removeTail();
  list.print();
  cout << endl;

  DoubleList dlist;
  dlist.push_back(45);
  dlist.push_back(3456);
  dlist.push_front(12);
  dlist.push_front(2);
  cout << dlist.front() << ' ' << dlist.back() << endl;
  dlist.print();
  dlist.pop_back();
  dlist.pop_front();
  dlist.print();
  return 0;
}
コード例 #2
0
SS DFStatement::buildSS(
 const StringList &inVarNameList,  const DoubleList &inCoefList,
 const StringList &outVarNameList, const DoubleList &outCoefList
) {
	//
	// FIRST, BUILD THE FILTER EQUATION
	//
	StringList::const_iterator inVarNameItr  = inVarNameList.begin();
	DoubleList::const_iterator inCoefItr     = inCoefList.begin();
	StringList::const_iterator outVarNameItr = outVarNameList.begin();
	DoubleList::const_iterator outCoefItr    = outCoefList.begin();

	BE be(  0, "+", BE( *inCoefItr, "*", *inVarNameItr )  );
	while( ++inVarNameItr != inVarNameList.end() ) {
		(void)++inCoefItr;
		be = BE(  be, "+", BE( *inCoefItr, "*", *inVarNameItr )  );
	}
	while( ++outVarNameItr != outVarNameList.end() ) {
		(void)++outCoefItr;
		be = BE(  be, "-", BE( *outCoefItr, "*", *outVarNameItr )  );
	}

	be = BE( be, "/", outCoefList.front() );
	be = BE( outVarNameList.front(), "=", be );

	//
	// SHIFT THE VARIABLES
	//
	SS ss(  IE( 1 ), be  );

	(void)--inVarNameItr;
	while( inVarNameItr != inVarNameList.begin() ) {
		StringList::const_iterator nxtInVarNameItr = inVarNameItr;
		(void)--nxtInVarNameItr;

		ss = SS(  ss, BE( *inVarNameItr, "=", *nxtInVarNameItr )  );
		inVarNameItr = nxtInVarNameItr;
	}

	(void)--outVarNameItr;
	while( outVarNameItr != outVarNameList.begin() ) {
		StringList::const_iterator nxtOutVarNameItr = outVarNameItr;
		(void)--nxtOutVarNameItr;

		ss = SS(  ss, BE( *outVarNameItr, "=", *nxtOutVarNameItr )  );
		outVarNameItr = nxtOutVarNameItr;
	}

	return ss;
}