Questions tagged [insertion]

place into or between other items in an enumeration

578 questions
-1
votes
1 answer

conversion from if statements to efficient for loop based solution for INSERTION SORT in Python

I have the following code that performs an insertion sort for 4 items in a list. It works, but it uses IF statements. I am interested in the various solutions that show a)conversion (based on my code and variables) to a simpler more efficient…
Compoot
  • 2,227
  • 6
  • 31
  • 63
-1
votes
1 answer

simplification of algorithm that uses if statements to incorporate efficient iteration

I have the following code that has a small error but otherwise performs what I believe is an insertion sort. I have two questions 1. Why is the index error occurring on running this? 2. How can I, for teaching and learning purposes, simplify the…
Compoot
  • 2,227
  • 6
  • 31
  • 63
-1
votes
1 answer

C# and negative array indices

I'm having a problem with getting this code (from Rosetta Code) to work as part of a greater Windows Form Project: It's a plain old insertion sort. Where it's going wrong is the bit involving the second for loop (The numbers generate just fine), in…
Mark Wild
  • 1
  • 2
-1
votes
2 answers

Unable to insert values into a list at the correct index

I receive a list of numbers and I want to sort them. the input looks like this: i:1,3,5,8 n:2 t:4,7 a:6 v:9 and comes in form of a txt file. The code looks like this: flat_list = [item for sublist in decks for item in sublist] p = [] for x in…
-1
votes
3 answers

Inserting element into array using c#

int[] arr = {4,3,6,7,9,12}; int n = arr.Length; n = n + 1; for (int i =n;i>2;i--) { arr[i-1] = arr[i-2]; } arr[0] = 4; The above code returning indexOutOfRangeexception.
vnu thaya
  • 3
  • 2
-1
votes
1 answer

C++ BST insertion

I'm implementing a BST using C++, but after I implemented the insert function, I found that I can only insert one node into the tree. I've tried many ways to solve the problem, but they didn't work out... Here's my implementation of insert…
-1
votes
2 answers

Unable to display the values of Linked List?

Here's my C++ program which is used to insert values at the beginning of the linked list. The logic of the program seems to be fine for me but it is unable to display the values of the list. I guess the problem is in the Print() function. Please…
-1
votes
1 answer

Runtime Analysis of Insertion Sort

I am trying to compute the run-time analysis of this Insertion Sort algorithm: 1) n = length[A] 2) count = 0 3) for (i=1; i<=n; i++) 4) for (j=1; j<=i; j++) 5) if A[j] <= 100 6) for (k=j; k<=j+2*i; k++) 7) …
Dani Ene
  • 23
  • 1
  • 7
-1
votes
2 answers

Insertion SQL and NOT NULL values

I've created a table schema and specified that for some attributes, values cannot be null. For one column of this table, values are to be imported from a column of some another table but the problem i am facing is that when i use insert statement to…
Aisha Javed
  • 169
  • 13
-1
votes
1 answer

C++ Insertion sort on a queue

I am trying to implement 'Insertion Sort' on two queues without using an array. Queue 1 - 4, 5, 11, 8, 3 Queue 2 - 2, 3, 4, 5, 2, 11 After the sorting they are as following : Queue 1 - 3, 4, 5, 8, 11 Queue 2 - 2, 2, 3, 4, 5, 11 They get sorted.…
-1
votes
1 answer

Insertion Sort Gone Wrong

I have an arraylist filled with random integers. I am trying to use insertion sort to sort and then print them on the screen. Everything works but the insertion sort... Not sure what is wrong can someone take a look at it and find what went wrong...…
user5344755
  • 47
  • 2
  • 6
-1
votes
1 answer

insertion in vb.net ( it returns syntax error in insert to statement in a textbox)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim con As New OleDbConnection("provider= microsoft.jet.oledb.4.0;data source=" & CurDir() & "\bilingual1.mdb") Dim reader As OleDbDataReader …
John
  • 1
  • 1
-1
votes
2 answers

Having trouble with text file input in Java

My professor really threw us into this project with a blindfold on. We didn't go into depth on using and inserting files into Java. I'm getting a ton of errors, which are most likely due to my incorrect insertion of the file. I saved the text file…
Lexi
  • 1
  • 2