Jump to content
Fórum Script Brasil
  • 0

Ordenação Pilha C++


Thiagoweb10

Question

Tenho um codigo que faz a ordenação dos dados vindo de um txt em bolha gostaria de saber com faço para organizar em pilha?

segue o codigo

private: System::Void OrganizaBolha()
         {
             
             Registro *registros = new Registro[dataGridView1->Rows->Count];

             
             for(int i = 0; i < dataGridView1->Rows->Count; i++)
             {
                 Registro reg;
                 
                 String^ sCodigo = dataGridView1->Rows[i]->Cells[0]->Value->ToString();
                 String^ sNome = dataGridView1->Rows[i]->Cells[1]->Value->ToString();
                 String^ sData = dataGridView1->Rows[i]->Cells[2]->Value->ToString();

                 for(int j = 0; j < 12; j++)
                 {
                     reg.Codigo[j] = sCodigo[j];
                 }

                 for(int j = 0; j < 44; j++)
                 {
                     reg.Nome[j] = sNome[j];
                 }

                 for(int j = 0; j < 5; j++)
                 {
                     reg.Data[j] = sData[j];
                 }

                 registros[i] = reg;
             }             

             

             Registro TMPs; 

            for(int i = 0; i < dataGridView1->Rows->Count; i++) { 

                for(int j = 0; j < dataGridView1->Rows->Count - i - 1; j++) { 

                    if (strcmp(registros[j].Codigo, registros[j + 1].Codigo) > 0) { 
                        TMPs = registros[j + 1]; 
                        registros[j + 1] = registros[j]; 
                        registros[j] = TMPs;
                    }
                }
            }

            int qtd = dataGridView1->Rows->Count;

            dataGridView1->Rows->Clear();
            
            array<String ^> ^ ColVals = gcnew array<String ^>(3);

            
            for(int i = 0; i < qtd; i++) {

                String^ sCodigo; 
                sCodigo = ""; 
                for(int Pos = 0; Pos < 12; Pos++) {
                    wchar_t Letra = registros[i].Codigo[Pos]; 
                    sCodigo += Letra;
                }

                String^ sNome; 
                sNome = ""; 
                for(int Pos = 0; Pos < 44; Pos++){ 
                    wchar_t Letra = registros[i].Nome[Pos]; 
                    sNome += Letra;
                }

                String^ sData;
                sData = ""; 
                for(int Pos = 0; Pos < 5; Pos++) {
                    wchar_t Letra = registros[i].Data[Pos];
                    sData += Letra;
                }

                ColVals[0] = sCodigo;
                ColVals[1] = sNome; 
                ColVals[2] = sData;

                dataGridView1->Rows->Add(ColVals);
            }
         }

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...