コード例 #1
0
ファイル: BST.cpp プロジェクト: clmitchell289/CSUMB-CST238
// Insert the Value into its proper place in the binary search tree
void BST::Insert(int Value)
{  Insert(Root, Value);  }
コード例 #2
0
 void Insert(Type key)
 {
     Insert(root , key);
 }
コード例 #3
0
ファイル: account_map.cpp プロジェクト: emfomy/dsa_final
////////////////////////////////////////////////////////////////////////////////
// Construct and insert an account                                            //
//                                                                            //
// Parameters:                                                                //
// id:        the ID                                                          //
// plaintext: the plain password                                              //
//                                                                            //
// Return Value:                                                              //
// true if insert succeeded, false if the ID already exists                   //
////////////////////////////////////////////////////////////////////////////////
 bool AccountMap::Emplace( const ID& id, const Plaintext& plaintext ) {
  if(Insert(id, plaintext)) {
    return true;
  }
  return false;
}
コード例 #4
0
void Tree::Insert(int data)
{
	Insert(Root, data);
}
コード例 #5
0
ファイル: List.hpp プロジェクト: changfeng777/DataStruct
	void PushBack(const T& x)
	{
		Insert(End(), x);
	}
コード例 #6
0
ファイル: Closed Fences.c プロジェクト: sunheehnus/USACO
void Compute(int i)
{
	int x1,x2,y1,y2;
	double edg1,edg2;
	x1=v[i].sx-tx;
	y1=v[i].sy-ty;
	x2=v[i].ex-tx;
	y2=v[i].ey-ty;
	if(y1==0&&y2==0)
		return;
	if(y1==0)
	{
		if(x1>0)
		{
			if(y2>0)
			{
				temp.sx=v[i].sx;
				temp.sy=v[i].sy;
				temp.ex=v[i].ex;
				temp.ey=v[i].ey;
				temp.edgs=0;
				temp.edge=atan2(y2,x2);
			}
			else
			{
				temp.sx=v[i].ex;
				temp.sy=v[i].ey;
				temp.ex=v[i].sx;
				temp.ey=v[i].sy;
				temp.edgs=atan2(y2,x2);
				temp.edge=0;
			}
		}
		else
		{
			if(y2>0)
			{
				temp.sx=v[i].ex;
				temp.sy=v[i].ey;
				temp.ex=v[i].sx;
				temp.ey=v[i].sy;
				temp.edgs=atan2(y2,x2);
				temp.edge=3.141592654;
			}
			else
			{
				temp.sx=v[i].sx;
				temp.sy=v[i].sy;
				temp.ex=v[i].ex;
				temp.ey=v[i].ey;
				temp.edgs=-3.141592654;
				temp.edge=atan2(y2,x2);
			}
		}
		Insert();
	}
	else if(y2==0)
	{
		if(x2>0)
		{
			if(y1>0)
			{
				temp.sx=v[i].ex;
				temp.sy=v[i].ey;
				temp.ex=v[i].sx;
				temp.ey=v[i].sy;
				temp.edgs=0;
				temp.edge=atan2(y1,x1);
			}
			else
			{
				temp.sx=v[i].sx;
				temp.sy=v[i].sy;
				temp.ex=v[i].ex;
				temp.ey=v[i].ey;
				temp.edgs=atan2(y1,x1);
				temp.edge=0;
			}
		}
		else
		{
			if(y1>0)
			{
				temp.sx=v[i].sx;
				temp.sy=v[i].sy;
				temp.ex=v[i].ex;
				temp.ey=v[i].ey;
				temp.edgs=atan2(y1,x1);
				temp.edge=3.141592654;
			}
			else
			{
				temp.sx=v[i].ex;
				temp.sy=v[i].ey;
				temp.ex=v[i].sx;
				temp.ey=v[i].sy;
				temp.edgs=-3.141592654;
				temp.edge=atan2(y1,x1);
			}
		}
		Insert();
	}
	else
	{
		edg1=atan2(y1,x1);
		edg2=atan2(y2,x2);
		if(edg1==edg2)
			return;
		if(edg1-edg2>3.141592654)
		{
			temp.sx=v[i].sx;
			temp.sy=v[i].sy;
			temp.ex=v[i].ex;
			temp.ey=v[i].ey;
			temp.edgs=edg1;
			temp.edge=3.141592654;
			Insert();
			temp.edgs=-3.141592654;
			temp.edge=edg2;
			Insert();
		}
		else if(edg2-edg1>3.141592654)
		{
			temp.sx=v[i].sx;
			temp.sy=v[i].sy;
			temp.ex=v[i].ex;
			temp.ey=v[i].ey;
			temp.edgs=-3.141592654;
			temp.edge=edg1;
			Insert();
			temp.edgs=edg2;
			temp.edge=3.141592654;
			Insert();
		}
		else
		{
			if(edg1<edg2)
			{
				temp.sx=v[i].sx;
				temp.sy=v[i].sy;
				temp.ex=v[i].ex;
				temp.ey=v[i].ey;
				temp.edgs=edg1;
				temp.edge=edg2;
			}
			else
			{
				temp.sx=v[i].ex;
				temp.sy=v[i].ey;
				temp.ex=v[i].sx;
				temp.ey=v[i].sy;
				temp.edgs=edg2;
				temp.edge=edg1;
			}
			Insert();
		}
	}
}
コード例 #7
0
ファイル: commandbar.cpp プロジェクト: jacklibj/r5
void wxGISMenu::MoveCommandRight(size_t nIndex)
{
	wxMenuItem *pMenuItem = Remove(FindItemByPosition(nIndex));
	Insert(nIndex + 1, pMenuItem);
	wxGISCommandBar::MoveCommandRight(nIndex);
}
コード例 #8
0
ファイル: Mesh.cpp プロジェクト: clones1201/Space
	Mesh* Mesh::CreateFromFBX(RenderSystem* pRenderSys, tstring const& filename)
	{ 
		try
		{
			tstring path = Core::GetInstance()->GetAssetsDir() + TEXT("/Models/") + filename;

			const aiScene* scene = aiImportFile(wstr2str(path).c_str(),
				aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_ConvertToLeftHanded | aiProcess_TransformUVCoords);

			Float3 min, max;

			if (scene == nullptr || scene->mNumMeshes == 0)
				throw std::exception("No Mesh in this file");

			Mesh* ret = new Mesh();

			for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex)
			{
				MeshPart* part = ret->CreatePart();
				aiMesh* pAiPart = scene->mMeshes[meshIndex];

				int32 numVertices = pAiPart->mNumVertices;
				int32 numFaces = pAiPart->mNumFaces;
				int32 numUVChannels = scene->mMeshes[meshIndex]->GetNumUVChannels();

				if (!pAiPart->HasFaces()
					|| !pAiPart->HasNormals()
					|| !pAiPart->HasPositions()
					|| !pAiPart->HasTextureCoords(0)
					|| !pAiPart->HasTangentsAndBitangents())
				{
					ret->RemovePart(part);
					continue;
				};

				min = Float3((float*)&(pAiPart->mVertices[0]));
				max = Float3((float*)&(pAiPart->mVertices[0]));

				part->m_pInputLayout.reset(new InputLayout{
					{ VertexElemType::Float3, ElemSemantic::Position, 0, 0, ElementClass::PerVertex, 0 },
					{ VertexElemType::Float3, ElemSemantic::Normal, 0, 0, ElementClass::PerVertex, 0 },
					{ VertexElemType::Float3, ElemSemantic::Tangent, 0, 0, ElementClass::PerVertex, 0 },
				});
				auto layout = part->m_pInputLayout;
				for (int32 i = 0; i < numUVChannels; ++i)
					layout->Insert(layout->End(),
					{ VertexElemType::Float2, ElemSemantic::TexCoord, (uint32)i, 0, ElementClass::PerVertex, 0 });

				uint32 stride = layout->GetVertexStride(0);
				byte* vertices = new byte[stride * numVertices];
				uint16* indices = new uint16[3 * numFaces];
				
				auto elemPosition = layout->Begin();
				auto elemNormal = elemPosition + 1;
				auto elemTangent = elemNormal + 1;

#define Get(V,i,stride,offset) (V + stride * i + offset)
				for (int32 i = 0; i < numVertices; ++i)
				{
					*(Float3*)Get(vertices, i, stride, elemPosition->AlignedByteOffset) = Float3((float*)&(pAiPart->mVertices[i]));
					*(Float3*)Get(vertices, i, stride, elemTangent->AlignedByteOffset) = Float3((float*)&(pAiPart->mTangents[i]));
					*(Float3*)Get(vertices, i, stride, elemNormal->AlignedByteOffset) = Float3((float*)&(pAiPart->mNormals[i]));

					auto elemTexCoord = elemTangent + 1;
					for (int32 j = 0; j < numUVChannels; ++j)
					{
						aiVector3D texcoord = pAiPart->mTextureCoords[j][i];
						*(Float2*)Get(vertices, i, stride, elemTexCoord->AlignedByteOffset) = Float2((float*)&(pAiPart->mTextureCoords[j][i]));
						++elemTexCoord;
					}

#if	UV_MIRROR
					float t = dot(cross(scene->mMeshes[meshIndex]->mNormals[i], scene->mMeshes[meshIndex]->mTangents[i]), scene->mMeshes[meshIndex]->mBitangents[i]);
					if (t < 0)
						vertices[i].Tangent = float3(-vertices[i].Tangent.r, vertices[i].Tangent.g, vertices[i].Tangent.b);
#endif

					min.x = std::min(min.x, pAiPart->mVertices[i].x);
					min.y = std::min(min.y, pAiPart->mVertices[i].y);
					min.z = std::min(min.z, pAiPart->mVertices[i].z);
					max.x = std::max(max.x, pAiPart->mVertices[i].x);
					max.y = std::max(max.y, pAiPart->mVertices[i].y);
					max.z = std::max(max.z, pAiPart->mVertices[i].z);
				}
				part->m_Size = std::max(max.x - min.x, std::max(max.y - min.y, max.z - min.z));
				part->m_Center = Float3((min.x + max.x) / 2.0f, (min.y + max.y) / 2.0f, (min.z + max.z) / 2.0f);

				for (long long i = 0; i < numFaces; ++i)
				{
					aiFace* face = &(scene->mMeshes[meshIndex]->mFaces[i]);
					indices[3 * i] = face->mIndices[0];
					indices[3 * i + 1] = face->mIndices[1];
					indices[3 * i + 2] = face->mIndices[2];
					assert(
						indices[3 * i] <= numVertices && 
						indices[3 * i + 1] <= numVertices &&
						indices[3 * i + 2] <= numVertices 
					);
				}

				part->m_NumPrimitives = numFaces;
				part->m_pVertexBuffer.reset(
					VertexBuffer::Create(pRenderSys, vertices, layout->GetVertexStride(0) * numVertices, layout->GetVertexStride(0)));
				part->m_pIndexBuffer.reset(
					IndexBuffer::Create(pRenderSys, (byte*)indices, sizeof(uint16) * 3 * numFaces, DataFormat::R16_UINT));

				delete vertices;
				delete indices;
			}

			aiReleaseImport(scene);
			return ret;
		}
		catch (std::exception& e)
		{
			Log(e.what());
			return nullptr;
		}
	}
コード例 #9
0
ファイル: studentsys.c プロジェクト: Dulun/Summer2015
int main()
{
	int n = -1;
	int flag = 0;
	int flag1;
	int save;
	struct Node * head;
	char fileName[20] = "0";

	flag = SignIn();           //登陆

	if(flag == 1)
	{
		head = InitLink();      //初始化
	}
	
	for(;;)  //各种功能 一直循环
	{
		fflush(stdin);				
		flag = 1;
		ReturnDesk();	

		system("clear");
		ShowDesk();
		fflush(stdin);
		scanf("%d", &n);
		fflush(stdin);	

		if(n == 0)
		{
			system("clear");
			FreeAllNodes(head);
			printf("\n\n\n\n\n\n               谢谢使用, ----made by Mr.Du 丶Lun\n\n\n\n\n\n");
			getch();
			exit(0);
		}//if

		if(n == 1)	
		{
			system("clear");
			Print(head);
		}//if
		if(n == 4)
		{
			system("clear");
			head = Sort(head);
			printf("sort over,new info:\n\n\n");
			Print(head);
		}
		if(n == 5)
		{
			system("clear");
			Print(head);
			Insert(head);
			system("clear");
			printf("insert over\n");
			Print(head);			
		}
		if(n == 6)
		{
			system("clear");
			Print(head);
			Remove(&head);
			system("clear");
			printf("remove over new info:\n");
			Print(head);
		}
		if(n == 8)
		{
			system("clear");
			Print(head);
			head =AddNodeBefore(head);
		}
		if(n == 9)
		{
			system("clear");
			Print(head);
			AddNodeAfter(head);
		}
		if(n == 10)
		{
			system("clear");
			printf("倒序排列为:\n");	
			head = Reverse(head);
			Print(head);
		}	
		if(n == 11)
		{
			system("clear");
			if(flag1 == -1)
			{
				Save_now_info(head, fileName);
				save = 1;
			}
			else
			{
				//printf("%d", flag);
				save = Save_info(head);
			}
			if(save == 1)
				printf("保存成功");
		}
		if(n == 12)
		{
			system("clear");
			head = Read_info(fileName);
			flag1 = -1;
			printf("\n");
			Print(head);
		}
		if(n == 2)
		{
			system("clear");
			Print(head);
			continueCreat(head);
		}
		if(n == 13)
		{
			system("clear");
			ChangePasswd();
			
		}
		if(n == 3)
		{
			system("clear");
			flag1 = 1;
			head = creatNewList();
		}
		if(n == 7)
		{
			system("clear");
			ChangeScore(head);
		}

	}//死循环
	
	getch();
}//main
コード例 #10
0
ファイル: BoundingBox.hpp プロジェクト: mark711/Cafu
 /// An equivalent to Insert(A), but more readable.
 void operator += (const ArrayT< Vector3T<T> >& A) { Insert(A); }
コード例 #11
0
ファイル: BoundingBox.hpp プロジェクト: mark711/Cafu
 /// An equivalent to Insert(BB), but more readable.
 void operator += (const BoundingBox3T<T>& BB) { Insert(BB); }
コード例 #12
0
ファイル: BoundingBox.hpp プロジェクト: mark711/Cafu
 /// An equivalent to Insert(A), but more readable.
 void operator += (const Vector3T<T>& A) { Insert(A); }
コード例 #13
0
 void lru_insert( Node *use_blk, Node *new_def ) { Insert(use_blk,new_def); }
コード例 #14
0
	//C-String Implementation of operator +=
	ZBasicString<A>& operator += (const char *_other) 
		{ Insert(Length(), _other); return *this; }
コード例 #15
0
bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
                                     double h, double pps, bool dB,
                                     float zoomMin, float zoomMax, float eMin, float eMax)
{
    bool upper;
    int ctr = (int)(r.height * zoomMax / (zoomMax - zoomMin));
    upper = (event.m_y - r.y < ctr);
    if(zoomMin == eMin)
        upper = true;

    mButton = event.GetButton();
    int clip_y = event.m_y - r.y;
    if(clip_y < 0) clip_y = 0;	//keeps point in rect r, even if mouse isn't
    if(clip_y > r.height) clip_y = r.height;

    mIsDeleting = false;
    double tleft = h - mOffset;
    double tright = tleft + (r.width / pps);
    int bestNum = -1;
    int bestDist = 10; // Must be within 10 pixel radius.

    double dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);

    mContourOffset = false;

    //   wxLogDebug(wxT("Y:%i Height:%i Offset:%i"), y, height, mContourOffset );

    int len = mEnv.Count();
    for (int i = 0; i < len; i++) {	//search for control point nearest click
        if (mEnv[i]->t >= tleft && mEnv[i]->t <= tright) {

            int x = int ((mEnv[i]->t + mOffset - h) * pps) + r.x;
            int y[4];
            int numControlPoints;

            // Outer control points
            y[0] = GetWaveYPos( mEnv[i]->val, zoomMin, zoomMax, r.height,
                                dB, true, dBr, false);
            y[1] = GetWaveYPos( -mEnv[i]->val, zoomMin, zoomMax, r.height,
                                dB, true, dBr, false);

            // Inner control points(contour)
            y[2] = GetWaveYPos( mEnv[i]->val, zoomMin, zoomMax, r.height,
                                dB, false, dBr, false);
            y[3] = GetWaveYPos( -mEnv[i]->val-.00000001, zoomMin, zoomMax,
                                r.height, dB, false, dBr, false);

            numControlPoints = 4;

            if (y[2] > y[3])
                numControlPoints = 2;

            if (!mMirror)
                numControlPoints = 1;

            for(int j=0; j<numControlPoints; j++) {

                int d = (int)(sqrt((double)(SQR(x-event.m_x) + SQR(y[j]-(event.m_y-r.y)))) + 0.5);
                if (d < bestDist) {
                    bestNum = i;
                    bestDist = d;
                    mContourOffset = (bool)(j > 1);
                }
            }
        }
    }

    if (bestNum >= 0) {
        mDragPoint = bestNum;
    }
    else {
        // Create new point
        double when = h + (event.m_x - r.x) / pps - mOffset;

        //      if (when <= 0 || when >= mTrackLen)
        //         return false;

        double v = GetValueAtX( event.m_x, r, h, pps );

        int ct = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
                              false, dBr, false) ;
        int cb = GetWaveYPos( -v-.000000001, zoomMin, zoomMax, r.height, dB,
                              false, dBr, false) ;
        if( ct <= cb || !mMirror ) {
            int t = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
                                 true, dBr, false) ;
            int b = GetWaveYPos( -v, zoomMin, zoomMax, r.height, dB,
                                 true, dBr, false) ;

            ct = (t + ct) / 2;
            cb = (b + cb) / 2;

            if(mMirror &&
                    (event.m_y - r.y) > ct &&
                    ((event.m_y - r.y) < cb))
                mContourOffset = true;
            else
                mContourOffset = false;
        }

        double newVal = ValueOfPixel(clip_y, r.height, upper, dB,
                                     zoomMin, zoomMax, eMin);

        //float MaxAmplify = ( mContourOffset ) ? 1.4 : 1.0;

        if(newVal > eMax)
            newVal = eMax;

        mDragPoint = Insert(when, newVal);
        mDirty = true;
    }

    mUpper = upper;

    mInitialWhen = mEnv[mDragPoint]->t;
    mInitialVal = mEnv[mDragPoint]->val;

    mInitialX = event.m_x;
    mInitialY = event.m_y+mContourOffset;

    return true;
}
コード例 #16
0
ファイル: GUIConfiguration.cpp プロジェクト: seebigsea/winscp
//---------------------------------------------------------------------------
void __fastcall TCopyParamList::Add(const UnicodeString Name,
  TCopyParamType * CopyParam, TCopyParamRule * Rule)
{
  Insert(Count, Name, CopyParam, Rule);
}
コード例 #17
0
void Envelope::Paste(double t0, Envelope *e)
{
    bool pointsAdded = false;

    if (e->mEnv.Count() == 0 && this->mEnv.Count() == 0 && e->mDefaultValue == this->mDefaultValue)
    {
        // msmeyer: The envelope is empty and has the same default value, so
        // there is nothing that must be inserted, just return. This avoids
        // the creation of unnecessary duplicate control points
        // MJS: but the envelope does get longer
        mTrackLen += e->mTrackLen;
        return;
    }
    if (this->mEnv.Count() != 0)
    {
        // inserting a clip with a possibly empty envelope into one with an envelope
        // so add end points to e, in case they are not there
        double leftval  = e->GetValue(0+e->mOffset);
        double rightval = e->GetValue(e->mTrackLen+e->mOffset);
        e->Insert(0, leftval);
        e->Insert(e->mTrackLen, rightval);
        pointsAdded = true;  // we need to delete them later so's not to corrupt 'e' for later use
    }

    t0 = wxMin(t0 - mOffset, mTrackLen);   // t0 now has origin of zero
    double deltat = e->mTrackLen;

    unsigned int i;
    unsigned int pos = 0;
    bool someToShift = false;
    bool atStart = false;
    bool beforeStart = false;
    bool atEnd = false;
    bool afterEnd = false;
    bool onPoint = false;
    unsigned int len = mEnv.Count();

    // get values to perform framing of the insertion
    double splitval = GetValue(t0 + mOffset);

    if(len != 0) {   // Not case 10: there are point/s in the envelope

        /*
        Cases:
        (see discussions on audacity-devel around 19/8/7 - 23/8/7 and beyond, "Envelopes and 'Join'")
        1  9     11  2    3 5  7   8   6 4   13              12
        0-----0--0---0    -----0---0------       --(0)----

        1   The insert point is at the beginning of the current env, and it is a control point.
        2   The insert point is at the end of the current env, and it is a control point.
        3   The insert point is at the beginning of the current env, and it is not a control point.
        4   The insert point is at the end of the current env, and it is not a control point.
        5   The insert point is not at a control point, and there is space either side.
        6   As 5.
        7   The insert point is at a control point, and there is space either side.
        8   Same as 7.
        9   Same as 5.
        10  There are no points in the current envelope (commonly called by the 'undo' stuff, and not in the diagrams).
        11  As 7.
        12  Insert beyond the RH end of the current envelope (should not happen, at the moment)
        13  Insert beyond the LH end of the current envelope (should not happen, at the moment)
        */

        // See if existing points need shifting to the right, and what Case we are in
        for (i = 0; i < len; i++) {
            if (mEnv[i]->t > t0)
                someToShift = true;
            else {
                pos = i; // last point not moved
                if ( fabs(mEnv[i]->t - t0) - 1/500000.0 < 0.0 ) // close enough to a point
                    onPoint = true;
            }
        }

        // In these statements, remember we subtracted mOffset from t0
        if( t0 < mTrackEpsilon )
            atStart = true;
        if( (mTrackLen - t0) < mTrackEpsilon )
            atEnd = true;
        if(0 > t0)
            beforeStart = true;  // Case 13
        if(mTrackLen < t0)
            afterEnd = true;  // Case 12

        // Now test for the various Cases, and try to do the right thing
        if(atStart) {   // insertion at the beginning
            if(onPoint) {  // first env point is at LH end
                mEnv[0]->t +=mTrackEpsilon;   // Case 1: move it R slightly to avoid duplicate point
                someToShift = true;  // there is now, even if there wasn't before
                //wxLogDebug(wxT("Case 1"));
            }
            else {
                Insert(t0 + mTrackEpsilon, splitval);   // Case 3: insert a point to maintain the envelope
                someToShift = true;
                //wxLogDebug(wxT("Case 3"));
            }
        }
        else {
            if(atEnd) { // insertion at the end
                if(onPoint) {  // last env point is at RH end, Case 2:
                    mEnv[0]->t -= mTrackEpsilon;  // move it L slightly to avoid duplicate point
                    //wxLogDebug(wxT("Case 2"));
                }
                else {   // Case 4:
                    Insert(t0 - mTrackEpsilon, splitval);   // insert a point to maintain the envelope
                    //wxLogDebug(wxT("Case 4"));
                }
            }
            else {
                if(onPoint) {  // Case 7: move the point L and insert a new one to the R
                    mEnv[pos]->t -= mTrackEpsilon;
                    Insert(t0 + mTrackEpsilon, splitval);
                    someToShift = true;
                    //wxLogDebug(wxT("Case 7"));
                }
                else {
                    if( !beforeStart && !afterEnd ) {// Case 5: Insert points to L and R
                        Insert(t0 - mTrackEpsilon, splitval);
                        Insert(t0 + mTrackEpsilon, splitval);
                        someToShift = true;
                        //wxLogDebug(wxT("Case 5"));
                    }
                    else {
                        if( beforeStart ) {  // Case 13:
                            //wxLogDebug(wxT("Case 13"));
                        }
                        else {   // Case 12:
                            //wxLogDebug(wxT("Case 12"));
                        }
                    }
                }
            }
        }

        // Now shift existing points to the right, if required
        if(someToShift) {
            len = mEnv.Count();  // it may well have changed
            for (i = 0; i < len; i++)
                if (mEnv[i]->t > t0)
                    mEnv[i]->t += deltat;
        }
        mTrackLen += deltat;
    }
    else {   // Case 10:
        if( mTrackLen == 0 ) // creating a new envelope
        {
            mTrackLen = e->mTrackLen;
            mOffset = e->mOffset;
            //wxLogDebug(wxT("Case 10, new env/clip: mTrackLen %f mOffset %f t0 %f"), mTrackLen, mOffset, t0);
        }
        else
        {
            mTrackLen += e->mTrackLen;
            //wxLogDebug(wxT("Case 10, paste into current env: mTrackLen %f mOffset %f t0 %f"), mTrackLen, mOffset, t0);
        }
    }

    // Copy points from inside the selection
    len = e->mEnv.Count();
    for (i = 0; i < len; i++)
        pos=Insert(t0 + e->mEnv[i]->t, e->mEnv[i]->val);

    /*   if(len != 0)
          for (i = 0; i < mEnv.Count(); i++)
             wxLogDebug(wxT("Fixed i %d when %.18f val %f"),i,mEnv[i]->t,mEnv[i]->val); */

    if(pointsAdded)
        while(e->mEnv.Count() != 0)
            e->Delete(0);  // they were not there when we entered this
}
コード例 #18
0
ファイル: sort.c プロジェクト: cmarcott/CIS2520
int main(int argc, char * argv[]) {
    int numOfLists, sizeOfLists, i, j, bufferItem;
    double bubBest1, bubWorst1, bubAvg1, bubBest2, bubWorst2, bubAvg2, bubBest3, bubWorst3, bubAvg3, sum1, sum2, sum3;
    List Lists[1000];
    List bufferList;
    clock_t start1,end1, start2, end2, start3, end3;
    srand(time(NULL));
    if ((argc < 3) || (argc > 3)) { /*Checks preconditions for program*/
        printf("**Invalid number of arguments to run program**\n\n**Program will terminate now\n");
        return 1;
    }
    numOfLists = atoi(argv[1]);
    sizeOfLists = atoi(argv[2]); /*only lists of size 1000 and up to 1000 lists are supported*/
    if ((numOfLists>1000) || (numOfLists<=2) || (sizeOfLists>1000) || (sizeOfLists<=2)) {
        printf("**Invalid integer entered**\nOnly integers between 3 and 1000 are allowed\nProgram will terminate now\n");
        return 1;
    }
    Initialize(&bufferList);
    for (i=0; i<sizeOfLists; i++) {  /*Create two mandatory Lists*/
        Insert(i+1, i, &Lists[0]);
        Insert(sizeOfLists-i, i, &Lists[1]);
    }
    for (i=2; i<numOfLists; i++) {
        for (j=0; j<sizeOfLists; j++) {
            bufferItem = (rand() %343+1);  /*Create random lists*/
            Insert(bufferItem, bufferList.size, &bufferList);
        }
        Lists[i] = bufferList;
        Initialize(&bufferList);
    }
    sum1=0;
    bubAvg1 = 0;
    start1 = clock();         /*Starts Timer*/
    BubbleSort1(Lists[0]);
    end1 = clock();
    bubBest1 = (double)(end1-start1)/CLOCKS_PER_SEC;

    start2 = clock();
    BubbleSort1(Lists[1]);
    end2 = clock();
    bubWorst1 = (double)(end2-start2)/CLOCKS_PER_SEC;

    for (i=0; i<numOfLists; i++) {
        start3 = clock();
        BubbleSort1(Lists[i]);
        end3 = clock();
        sum1 = ((double)(end3-start3)/CLOCKS_PER_SEC);
        bubAvg1 = bubAvg1 + sum1;                  /*Finds the Average*/
    }
    bubAvg1 = bubAvg1/numOfLists;

    printf("\nBubbleSort1\n%f\n%f\n%f\n", bubBest1, bubAvg1, bubWorst1);

    sum2=0;
    bubAvg2 = 0;
    start1 = clock();
    BubbleSort2(Lists[0]);
    end1 = clock();
    bubBest2 = (double)(end1-start1)/CLOCKS_PER_SEC;

    start2 = clock();
    BubbleSort2(Lists[1]);
    end2 = clock();
    bubWorst2 = (double)(end2-start2)/CLOCKS_PER_SEC;

    for (i=0; i<numOfLists; i++) {
        start3 = clock();
        BubbleSort2(Lists[i]);
        end3 = clock();
        sum2 = ((double)(end3-start3)/CLOCKS_PER_SEC);
        bubAvg2 = bubAvg2 + sum2;
    }
    bubAvg2 = bubAvg2/numOfLists;


    printf("\nBubbleSort2\n%f\n%f\n%f\n", bubBest2, bubAvg2, bubWorst2);

    sum3=0;
    bubAvg3 = 0;
    start1 = clock();
    MergeSort(&Lists[0], 0, Lists[0].size-1);
    end1 = clock();
    bubBest3 = (double)(end1-start1)/CLOCKS_PER_SEC;

    start2 = clock();
    MergeSort(&Lists[1], 0, Lists[1].size-1);
    end2 = clock();
    bubWorst3 = (double)(end2-start2)/CLOCKS_PER_SEC;

    for (i=0; i<numOfLists; i++) {
        start3 = clock();
        MergeSort(&Lists[i], 0, Lists[i].size-1);
        end3 = clock();
        sum3 = ((double)(end3-start3)/CLOCKS_PER_SEC);
        bubAvg3 = bubAvg3 + sum3;
    }
    bubAvg3 = bubAvg3/numOfLists;

    printf("\nMergeSort\n%f\n%f\n%f\n", bubBest3, bubAvg3, bubWorst3);

    return EXIT_SUCCESS;
}
コード例 #19
0
ファイル: Closed Fences.c プロジェクト: sunheehnus/USACO
void Insert()
{
	int j;
	for(j=tot;j>0;j--)
	{
		cur=tar[j];
		if(cur.edgs==temp.edgs)
		{
			if(Yes())
			{
				if(cur.edge==temp.edge)
				{
					tar[j]=temp;
					return;
				}
				else if(cur.edge<temp.edge)
				{
					temp.edgs=tar[j].edge;
					tar[j].sx=temp.sx;
					tar[j].sy=temp.sy;
					tar[j].ex=temp.ex;
					tar[j].ey=temp.ey;
					Insert();
					return;
				}
				else
				{
					tar[j].edgs=temp.edge;
					tot++;
					tar[tot]=temp;
					return;
				}
			}
			else
			{
				if(cur.edge==temp.edge)
				{
					return;
				}
				else if(cur.edge<temp.edge)
				{
					temp.edgs=tar[j].edge;
					Insert();
					return;
				}
				else
				{
					tar[j].edgs=temp.edge;
					tot++;
					tar[tot]=cur;
					tar[tot].edge=temp.edge;
					return;
				}
			}
		}
		else if(cur.edge==temp.edge)
		{
			if(Yes())
			{
				if(cur.edgs<temp.edgs)
				{
					tar[j].edge=temp.edgs;
					tot++;
					tar[tot]=temp;
					return;
					
				}
				else
				{
					temp.edge=tar[j].edgs;
					tar[j].sx=temp.sx;
					tar[j].sy=temp.sy;
					tar[j].ex=temp.ex;
					tar[j].ey=temp.ey;
					Insert();
					return;
				}
			}
			else
			{
				if(cur.edgs<temp.edgs)
				{
					tar[j].edge=temp.edgs;
					tot++;
					tar[tot]=tar[j];
					tar[tot].edgs=temp.edgs;
					tar[tot].edge=temp.edge;
					return;
					
				}
				else
				{
					temp.edge=tar[j].edgs;
					Insert();
					return;
				}
			}
		}
	}
	tot++;
	tar[tot]=temp;
}
コード例 #20
0
ファイル: csstring.cpp プロジェクト: garinh/cs
csStringBase &csStringBase::Insert (size_t iPos, char iChar)
{
  csStringBase s(iChar);
  return Insert(iPos, s);
}
コード例 #21
0
ファイル: Variant.cpp プロジェクト: lailongwei/llbc
std::pair<DictIter, bool> LLBC_Variant::Insert(const Dict::key_type &key, const Dict::mapped_type &val)
{
    return Insert(Dict::value_type(key, val));
}
コード例 #22
0
//------------------------------------------------------------------------------
//
// 	Function Name:	CMLListCtrl::Add()
//
//	Parameters:		pMLElement - pointer to element to be added to the list control
//
// 	Return Value:	TRUE if successful
//
// 	Description:	This function is called to add a new element to the list box
//
//------------------------------------------------------------------------------
BOOL CMLListCtrl::Add(CMLListCtrlElement* pMLElement, BOOL bResizeColumns)
{
	return Insert(pMLElement, -1, bResizeColumns);
}
コード例 #23
0
ファイル: jvmsym.c プロジェクト: Ukusbobra/open-watcom-v2
static char *DoDemangle( char *name, unsigned *add, unsigned *len, char *sig )
{
    char        *p;
    unsigned    first;

    switch( *sig++ ) {
    case SIGNATURE_ARRAY:
        Insert( name, add, len, " []" );
        while( isdigit( *sig ) ) ++sig;
        sig = DoDemangle( name, add, len, sig );
        break;
    case SIGNATURE_CLASS:
        p = strchr( sig, SIGNATURE_ENDCLASS );
        *p = '\0';
        Insert( name, add, len, sig );
        sig = p + 1;
        break;
    case SIGNATURE_FUNC:
        *add += Insert( name, add, len, "(" );
        first = 1;
        for( ;; ) {
            if( *sig == SIGNATURE_ENDFUNC ) break;
            if( !first ) {
                *add += Insert( name, add, len, "," );
            }
            sig = DoDemangle( name, add, len, sig );
            *add = *len;
            first = 0;
        }
        Insert( name, add, len, ")" );
        *add = 0;
        Insert( name, add, len, " " );
        sig = DoDemangle( name, add, len, sig+1 );
        *add = *len;
        break;
    case SIGNATURE_BYTE:
        *add += Insert( name, add, len, "byte" );
        break;
    case SIGNATURE_CHAR:
        *add += Insert( name, add, len, "char" );
        break;
    case SIGNATURE_FLOAT:
        *add += Insert( name, add, len, "float" );
        break;
    case SIGNATURE_DOUBLE:
        *add += Insert( name, add, len, "double" );
        break;
    case SIGNATURE_INT:
        *add += Insert( name, add, len, "int" );
        break;
    case SIGNATURE_LONG:
        *add += Insert( name, add, len, "long" );
        break;
    case SIGNATURE_SHORT:
        *add += Insert( name, add, len, "short" );
        break;
    case SIGNATURE_VOID:
        *add += Insert( name, add, len, "void" );
        break;
    case SIGNATURE_BOOLEAN:
        *add += Insert( name, add, len, "boolean" );
        break;
    }
    return( sig );
}
コード例 #24
0
wxTaskBarJumpListItem*
wxTaskBarJumpListCategory::Prepend(wxTaskBarJumpListItem *item)
{
    return Insert(0, item);
}
コード例 #25
0
ファイル: List.hpp プロジェクト: changfeng777/DataStruct
	void PushFront(const T& x)
	{
		Insert(Begin(), x);
	}
コード例 #26
0
void DINGOOMidiService::buildDriverList() {// Here we just loop over existing Midi out and create a midi device for each of them.

	Insert(new DINGOOSerialMidiDevice()) ;

} ;
コード例 #27
0
ファイル: TreeNode.cpp プロジェクト: GordonSmith/eclide
HTREEITEM CTreeNode::InsertBelow(WTL::CTreeViewCtrlEx &tc, HTREEITEM parent, bool bLast)
{
	return Insert(tc, parent, bLast ? TVI_LAST : TVI_SORT);
}
コード例 #28
0
void Envelope::testMe()
{
    double t0=0, t1=0;

    SetInterpolateDB(false);
    Mirror(false);

    SetDefaultValue(0.5);
    Flatten(0.5);
    checkResult( 1, Integral(0.0,100.0), 50);
    checkResult( 2, Integral(-10.0,10.0), 10);

    SetDefaultValue(1.0);
    Flatten(0.5);
    checkResult( 3, Integral(0.0,100.0), 50);
    checkResult( 4, Integral(-10.0,10.0), 10);
    checkResult( 5, Integral(-20.0,-10.0), 5);

    SetDefaultValue(0.5);
    Flatten(0.5);
    Insert( 5.0, 0.5 );
    checkResult( 6, Integral(0.0,100.0), 50);
    checkResult( 7, Integral(-10.0,10.0), 10);

    SetDefaultValue(0.5);
    Flatten(0.0);
    Insert( 0.0, 0.0 );
    Insert( 5.0, 1.0 );
    Insert( 10.0, 0.0 );
    t0 = 10.0 - .1;
    t1 = 10.0 + .1;
    double result = Integral(0.0,t1);
    double resulta = Integral(0.0,t0);
    double resultb = Integral(t0,t1);
    // Integrals should be additive
    checkResult( 8, result - resulta - resultb, 0);

    SetDefaultValue(0.5);
    Flatten(0.0);
    Insert( 0.0, 0.0 );
    Insert( 5.0, 1.0 );
    Insert( 10.0, 0.0 );
    t0 = 10.0 - .1;
    t1 = 10.0 + .1;
    checkResult( 9, Integral(0.0,t1), 5);
    checkResult( 10, Integral(0.0,t0), 4.999);
    checkResult( 11, Integral(t0,t1), .001);

    WX_CLEAR_ARRAY(mEnv);
    Insert( 0.0, 0.0 );
    Insert( 5.0, 1.0 );
    Insert( 10.0, 0.0 );
    checkResult( 12, NumberOfPointsAfter( -1 ), 3 );
    checkResult( 13, NumberOfPointsAfter( 0 ), 2 );
    checkResult( 14, NumberOfPointsAfter( 1 ), 2 );
    checkResult( 15, NumberOfPointsAfter( 5 ), 1 );
    checkResult( 16, NumberOfPointsAfter( 7 ), 1 );
    checkResult( 17, NumberOfPointsAfter( 10 ), 0 );
    checkResult( 18, NextPointAfter( 0 ), 5 );
    checkResult( 19, NextPointAfter( 5 ), 10 );
}
Position
readFromFile(SearchTree Tree)
{
	 FILE *file_Ptr ;
	 char* fileName = "sherlock.txt";
	 int repeat = 0;
	 int i=0;
	 char charAt;
	// char *word;
	 int stringValue =0;

	 fileName = ((char*)malloc(256*sizeof(char)));
	 temparray = ((char*)malloc(22*sizeof(char)));

	 do
	 {
	 printf("\n Enter FileName : ");
	 scanf(" %s",fileName);

	 file_Ptr= fopen( fileName , "r" ) ;

	while (!feof(file_Ptr))
	{
		char buffer[100];
		char* word = malloc(sizeof(fscanf(file_Ptr, "%s", buffer)));
		stringValue =0;

		fscanf(file_Ptr, "%s", word);

		// creates a node value and makes all chars lower case
		for(i=0;i<strlen(word);i++)
		{
			word[i] = tolower(word[i]);
		}

		//printf(" %s ", word);

		char* tempword = ((char*)malloc(22*sizeof(char)));
		char* tempword2 = ((char*)malloc(22*sizeof(char)));
		int word1count =0;
		int word2count =0;
		int punct =0;

		for(i=0;i<strlen(word);i++)
		{

		charAt = word[i];
		if( !isdigit( charAt ))
		{
				if( isalpha( charAt ) )
				{
					// printf( "\n Letter %c Found" , tolower(charAt )) ;
					 if(punct==0){
						 tempword[word1count] = charAt;
						 word1count++;
					 }
					 else{
						 tempword2[word2count] = charAt;
						 word2count++;
					 }
				}
				else if( ispunct( charAt ) )
				{
					//printf( "\n Punctuation Found %c\n", charAt ) ;
					punct=1;
				}
				else if( isspace( charAt ) )
				{
				//	printf( "\n Space Found\n" ) ;
				}
			 }
		}

	//	printf("\n word1 %s\n",tempword);
	//	printf(" word2 %s\n",tempword2);

		strcpy(word,tempword);
		stringValue =0;
		for(i=0;i<strlen(word);i++)
		{
			stringValue += *word;
		}
		//printf("\n String  : %s\n",word);
		//printf(" At Node : %d\n",stringValue);

		strcpy(temparray,word);
		//printf(" temp array %s", temparray);

		if ((strcmp(word, "endoffile"))==0)
		{
					//	printf("END");
						feof(file_Ptr);
		}
		else
		{

		Tree = Insert( word, stringValue, Tree );

		if(punct==1)
		{
			strcpy(word,tempword2);
			stringValue =0;
					for(i=0;i<strlen(word);i++)
					{
						stringValue += *word;
					}
					//printf("\n String  : %s\n",word);
					//printf(" At Node : %d\n",stringValue);

					strcpy(temparray,word);
					//printf(" temp array %s", temparray);

			Tree = Insert( word, stringValue, Tree );
		}
		}// end of EOF check
	} // while not the end of file

	 if( file_Ptr != NULL ) {

	    fclose( file_Ptr ) ;
	    printf("\n File '%s' closed. \n",fileName);
	    repeat=0;
	  }
	  else  {
	    if( file_Ptr == NULL) printf( "\n Unable to open file.\n" ) ;
	    repeat=1;

	}// end of EOF check
	 }while(repeat==1);

	 return Tree;
}
コード例 #30
0
void AVLTree::Insert(TreeNode * &node, TreeNode *parent, int x, QAnimationGroup *group)
{
    if (group && parent)
        group->addAnimation(parent->getTurnRedAnim());
    if (node == NULL)
    {
        QParallelAnimationGroup *anim = new QParallelAnimationGroup;
        node = new TreeNode();
        view->addItem(node);
        node->data = x;
        node->setPos(parent ? parent->pos() : QPointF(0, 0));
        anim->addAnimation(node->getFadeInAnim());
        if (group)
        {
            anim->addAnimation(node->setParent(parent));
            anim->addAnimation(getPosAnim());
            group->addAnimation(anim);
            if (parent)
                group->addAnimation(parent->getTurnBlackAnim());
        }
        else
        {
            anim->start(QAbstractAnimation::DeleteWhenStopped);
        }
        return;
    }
    TreePath *path;
    if (group && parent)
    {
        path = new TreePath(parent, node, view);
        group->addAnimation(path->getToSonAnim());
    }
    if (node->data > x)
    {
        Insert(node->Lson, node, x, group);
        if (group && parent)
            group->addAnimation(path->getToParentAnim());
        if (2 == height(node->Lson) - height(node->Rson))
        {
            if (x < node->Lson->data)
                LL(node, group);
            else
                LR(node, group);
        }
    }
    else if (node->data < x)
    {
        Insert(node->Rson, node, x, group);
        if (group && parent)
            group->addAnimation(path->getToParentAnim());
        if (2 == height(node->Rson) - height(node->Lson))
        {
            if (x > node->Rson->data)
                RR(node, group);
            else
                RL(node, group);
        }
    }
    else if (group && parent)
        group->addAnimation(path->getToParentAnim());
    if (group && parent)
        group->addAnimation(parent->getTurnBlackAnim());
    node->h = max(height(node->Lson), height(node->Rson)) + 1;
}