logo

C++'da 2B Vektörü Sıralama | Set 3 (Sütun sayısına göre)

Aşağıdaki set 1 ve set 2'de 2 boyutlu vektörün sınıflandırılmasına ilişkin bazı durumları tartıştık.
C++'da 2B Vektörü Sıralama | Set 1 (Satır ve sütuna göre)  
C++'da 2B Vektörü Sıralama | Set 2 (Satır ve sütuna göre azalan sırada)
Bu makalede daha fazla vaka tartışılmaktadır
Bu setin yayınlanan makalelerinden birinde belirtildiği gibi, bir 2D Vector'un farklı sayıda sütuna sahip satırları da olabilir. Bu özellik, tüm satırların aynı sayıda sütuna sahip olduğu 2B Diziden farklıdır.
 

CPP
// C++ code to demonstrate 2D Vector // with different no. of columns #include   #include // for 2D vector using namespace std; int main() {  // Initializing 2D vector 'vect' with  // values  vector< vector<int> > vect{{1 2}  {3 4 5}  {6}};  // Displaying the 2D vector  for (int i=0; i<vect.size(); i++)  {  //loop till the size of particular  //row  for (int j=0; j<vect[i].size() ;j++)  cout << vect[i][j] << " ";  cout << endl;  }  return 0; } 

Çıkış: 
 



Sree Ramanujan
1 2 3 4 5 6

Zaman Karmaşıklığı: O(n*m) n satır sayısı ve m sütun sayısıdır

Uzay Karmaşıklığı: Ç(n*m)


Durum 5: 2D Vektörün numaraya göre sıralanması. artan sırada satırdaki sütunların sayısı.
Bu tür sıralamada 2 boyutlu vektör bir numaraya göre sıralanır. artan sırada sütun. Bu, kullanıcı tanımlı açık işleve çağrı olarak sort()'daki üçüncü bir argümanın iletilmesiyle gerçekleştirilir.
 



android.process.acore durmaya devam ediyor
CPP
// C++ code to demonstrate sorting of // 2D vector on basis of no. of columns // in ascending order #include   #include // for 2D vector #include   // for sort() using namespace std; // Driver function to sort the 2D vector // on basis of a no. of columns in  // ascending order bool sizecom(const vector<int>& v1 const vector<int>& v2) {  return v1.size() < v2.size(); } int main() {  // Initializing 2D vector 'vect' with  // values  vector< vector<int> > vect{{1 2}  {3 4 5}  {6}};  // Displaying the 2D vector before sorting  cout << "The Matrix before sorting is:n";  for (int i=0; i<vect.size(); i++)  {  //loop till the size of particular  //row  for (int j=0; j<vect[i].size() ;j++)  cout << vect[i][j] << " ";  cout << endl;  }  //Use of 'sort()' for sorting on  //basis of no. of columns in  //ascending order.  sort(vect.begin() vect.end() sizecom);  // Displaying the 2D vector after sorting  cout << "The Matrix after sorting is:n";  for (int i=0; i<vect.size(); i++)  {  //loop till the size of particular  //row  for (int j=0; j<vect[i].size() ;j++)  cout << vect[i][j] << " ";  cout << endl;  }  return 0; } 

Çıkış: 
 

The Matrix before sorting is: 1 2 3 4 5 6 The Matrix after sorting is: 6 1 2 3 4 5 

Zaman Karmaşıklığı: O (nlog(n))

Uzay Karmaşıklığı: Ç(n*m)




Durum 6: 2D Vektörün numaraya göre sıralanması. azalan sırada satırdaki sütunların sayısı.
Bu tür sıralamada 2 boyutlu vektör bir numaraya göre sıralanır. azalan sırada sütun. Bu, kullanıcı tanımlı açık işleve çağrı olarak sort()'daki üçüncü bir argümanın iletilmesiyle gerçekleştirilir.
 

CPP
// C++ code to demonstrate sorting of // 2D vector on basis of no. of columns // in descending order #include   #include // for 2D vector #include   // for sort() using namespace std; // Driver function to sort the 2D vector // on basis of a no. of columns in  // descending order bool sizecom(const vector<int>& v1 const vector<int>& v2) {  return v1.size() > v2.size(); } int main() {  // Initializing 2D vector 'vect' with  // values  vector< vector<int> > vect{{1 2}  {3 4 5}  {6}};  // Displaying the 2D vector before sorting  cout << "The Matrix before sorting is:n";  for (int i=0; i<vect.size(); i++)  {  //loop till the size of particular  //row  for (int j=0; j<vect[i].size() ;j++)  cout << vect[i][j] << " ";  cout << endl;  }  //Use of 'sort()' for sorting on  //basis of no. of columns in  //descending order.  sort(vect.begin() vect.end() sizecom);  // Displaying the 2D vector after sorting  cout << "The Matrix after sorting is:n";  for (int i=0; i<vect.size(); i++)  {  //loop till the size of particular  //row  for (int j=0; j<vect[i].size() ;j++)  cout << vect[i][j] << " ";  cout << endl;  }  return 0; } 

Çıkış: 
 

The Matrix before sorting is: 1 2 3 4 5 6 The Matrix after sorting is: 3 4 5 1 2 6 

Zaman Karmaşıklığı: O (nlog(n))

prolog nedir

Uzay Karmaşıklığı: Ç(n*m)