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 });             }            

Insertion sort and let us consider an array of size 10 for Data Structure in 'C'

Insertion sort: 

                 In this technique of sorting, the fact of inserting the pivotal element  at its proper position from n (size of the array) number of elements is used. The pivotal element to be inserted is picked from the array itself. The selected pivotal element is inserted at the position from the left part of the array that is treated as sorted.
                   Initially the first element of the array is treated as left part of the array and being one element that is treated as sorted part of the array. The first pivotal element that is selected for insertion is the second element of the array. the pivotal element is compared with the first element and if the first element is greater than the pivotal element, then it is moved to the second position. Now we remain with no elements compared to be compared in the left part, the position where the pivotal element is found as the first position. The pivotal element is inserted at the first position to over the pass. If the first element is not greater than the pivotal element then the position of the pivotal element is right and remains at the same place. After the first pass the left part of the array containing two elements is in sorted order.
                 In the further passes the element of the unsorted part of the array is selected as pivotal element and a position to insert it in the sorted part (left array) of the array is found by shifting the sorted elements to the right if required. So after every pass the pivotal element is inserted at its proper position in the array. As the insertion operation is being performed to insert the pivotal element, this technique of sorting the array is called as ‘’insertion sort’’.

 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 any order. So to arrange the elements in ascending order we can apply the insertion sort.
In the first pass, we select the element 18 is pivotal element. The left part of the of the array before the pivotal element contains only one element and it is the sorted part of the array. 18 is compared with 91,91 is greater than 18. So, 91 is shifted to the right by one position. Now there are no elements to be compared in the sorted part of the array with the pivotal element. Now the pivotal element is inserted at first position of the array. After this pass the array looks as follows: [sorted elements-BOLD, pivotal element – underlined].
                                    18 91 22 43 34 10 88 11 33 77
In the second pass, 22 is selected as pivotal element. 22 is compared with 91, as 91 is greater then 22, 91 is shifted towards its right by one position. Again 22 is compared with 18,18 is not greater then the pivotal element 22. So, the comparison is stopped because the position where the pivotal element 22 is to be inserted is found. The pivotal element 22 is inserted at second position. After this pass the array looks as follows:
                                     18 22 91 43 34 10 88 11 33 77
In the third pass, 43 is selected as pivotal element from the unsorted part of the array. 43 is compared with 91 and  91 is shifted towards its right by one position. 43 is again compared with 22. 22 is not greater then 43 and comparison is stops. 43 is inserted at third element of array.  After this pass the array looks as follows:
                                     18 22 43 91 34 10 88 11 33 77
In the fourth pass, 34 is selected as pivotal element from the unsorted part of the array. 34 is compared with 91 and 91 is shifted towards its right by one position. 34 is again compared with 43. 43 is also right shifted by one position. 34 is now comparison with 22. 22 is not greater then 34 and comparison stops. 34 is inserted at third element of array.  After this pass the array looks as follows:
                                     18 22 34 43 91 10 88 11 33 77
In the fifth pass, 10 is selected as pivotal element from the unsorted part of the array. As 10 smaller then all the sorted elements of the left part of the array, each element is shifted to right by one position respectively. 10 is inserted as the first element of array.  After this pass the array looks as follows:
                                     10 18 22 34 43 91 88 11 33 77
In the sixth pass, 88 is selected as pivotal element from the unsorted part of the array. 88 is compared with 91 and  91 is shifted towards its right by one position because it is greater then 88. 88 is now compared with 43. and comparison is stops. 88 is inserted at sixth element of array.  After this pass the array looks as follows:
                                     10 18 22 34 43 88 91 11 33 77
In the seventh pass, 11 is selected as pivotal element from the unsorted part of the array. 11 is compared with all the element up to 18 and they are  shifted to right by one position respectively. The comparison is stops when 11 is compared with 10. So, 11 is inserted at second element of the array.  After this pass the array looks as follows:
                                     10 11 18 22 34 43 88 91 33 77
In the eighth pass, 33 is selected as pivotal element from the unsorted part of the array. 33 is compared with all the element up to 34 and they are  shifted to right by one position respectively. The comparison is stops when 33 is compared with 22. So, 33 is inserted at fifth element of the array.  After this pass the array looks as follows:
                                     10 11 18 22 33 34 43 88 91 77
In the ninth and final pass, 77 is selected as pivotal element from the unsorted part of the array. 77 is compared with 91 and 88 and they are shifted to right by one position respectively. The comparison is stops when 77 is compared with 43. So, 77 is inserted at eighth element of the array.  After this pass the array looks as follows:
                                     10 11 18 22 33 34 43 77 88 91 

Comments

Popular 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 });             }            

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

Print the asp.net webpage using button

Introduction Today i am talking about printing, and how to print the content or you can say selected content in asp.net. If you have a webpage and you want to print this then you have to choose command key (ctrl+p) for that. Also you want to print the selected part then you have to select the text first then you have to use command key. But sometimes your selected page could not printed. So many websites provide the printing facilities on the webpage. Today i am talking about the same topics here. Lets take a simple example to demonstrate the topic. Source code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="printpage.aspx.cs" Inherits="printpage" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title></title> <script> function printpage() { var getpanel = document.getElementById("<%= Panel1.ClientID%>"); var MainWin