Skip to main content

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Example of Selection sort for Data Structure in 'C'

Selection sort:

            In this technique of sorting, the fact of selecting the minimum element from n (size of the array) number of elements is used. The selected minimum element is interchanged with the first element of the array. Then leaving the first element, the minimum element is again picked from the remaining n-1 elements and interchanged with the second element. The same process of selecting minimum element and interchanging it from the respective element is repeated to obtain the sorted array. In total n-1 passes are applied to obtain the sorted array. As we select the minimum element in every pass this technique of sorting the elements is called as Selection sort. Let us understand this technique with the help of an analytical example before going into the algorithm and C function. Let us consider an array of size 10 with the following elements:

                  91 18 22 43 34 10 88 11 33 77
We can observe the elements and see that the elements are not in order. So to arrange the elements in ascending order we can apply the selection sort. 

In the first pass, we select the minimum element from the 10 elements as 10 with index 6. Interchange the element 10 with the element 91 (first element of the array). After this pass the array looks as follows:
                 10 18 22 43 34 91 88 11 33 77
In the second pass, we select the minimum element from 9 elements leaving the first element (as it is already sorted) as 11 with index 8. Interchange the element 11 with 18 (second element of the array). After this pass the array looks as follows:
                  10 11 22 43 34 91 88 18 33 77
In the third pass, we select the minimum element from 8 elements leaving the first two elements (as they are already sorted) as 18 with index 8. Interchange the element 18 with 22 (third element of the array). After this pass the array looks as follows:
                   10 11 18 43 34 91 88 22 33 77
In the fourth pass, we select the minimum element from 7 elements leaving the first three elements (as they are already sorted) as 22 with index 8. Interchange the element 22 with 43 (fourth element of the array). After this pass the array looks as follows:
                     10 11 18 22 34 91 88 43 33 77
 In the fifth pass, we select the minimum element from 6 elements leaving the first four elements (as they are already sorted) as 33 with index 9. Interchange the element 33 with 34 (fifth element of the array). After this pass the array looks as follows:
                      10 11 18 22 33 91 88 43 34 77
In the six pass, we select the minimum element from 5 elements leaving the first five elements (as they are already sorted) as 34 with index 9. Interchange the element 34 with 91 (sixth element of the array). After this pass the array looks as follows:
                       10 11 18 22 33 34 88 43 91 77
In the seventh pass, we select the minimum element from 4 elements leaving the first six elements (as they are already sorted) as 43 with index 8. Interchange the element 43 with 88 (seventh element of the array). After this pass the array looks as follows:
                       10 11 18 22 33 34 43 88 91 77
In the eighth pass, we select the minimum element from 3 elements leaving the first seven elements (as they are already sorted) as 77 with index 10. Interchange the element 77 with 88 (eighth element of the array). After this pass the array looks as follows:
                        10 11 18 22 33 34 43 77 91 88
In the ninth pass, we select the minimum element from 2 elements leaving the first three elements (as they are already sorted) as 88 with index 10. Interchange the element 77 with 91 (ninth element of the array). After this pass the array looks as follows:
                         10 11 18 22 33 34 43 77 88 91
The ninth pass is the last pass. We can observe from the last pass that after that pass we remain with the largest element of the array and is placed at its proper place. That is why we require only n-1 in this case 9 passes to sort the array.

Comments

Popular Post

Polynomial representation using Linked List for Data Structure in 'C'

Polynomial representation using Linked List The linked list can be used to represent a polynomial of any degree. Simply the information field is changed according to the number of variables used in the polynomial. If a single variable is used in the polynomial the information field of the node contains two parts: one for coefficient of variable and the other for degree of variable. Let us consider an example to represent a polynomial using linked list as follows: Polynomial:      3x 3 -4x 2 +2x-9 Linked List: In the above linked list, the external pointer ‘ROOT’ point to the first node of the linked list. The first node of the linked list contains the information about the variable with the highest degree. The first node points to the next node with next lowest degree of the variable. Representation of a polynomial using the linked list is beneficial when the operations on the polynomial like addition and subtractions are performed. The resulting polynomial can also

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Memory representation of Linked List Data Structures in C Language

                                 Memory representation of Linked List              In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.                Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:       Suppose next node is allocated at an address 506, so the list becomes,   Suppose next node is allocated with an address with an address 10,s the list become, The other way to represent the linked list is as shown below:  In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of