Questions tagged [sorted]

This tag refers to a collection of items that has already been arranged in some specific order.

Use this tag for questions dealing with already sorted collections (i.e. reordering them, adding elements to them while still preserving the order, etc.).

297 questions
-2
votes
1 answer

Bubble sort all but first spot

If I change the condition (i < n -1) to (i < n) it glitches, and as it is now, all but the first position [0] gets sorted. int sortIndexByDate(Match match[], int n) { int i, j, sum[n], swapped; for (i = 0; i < n; i++) sum[i] =…
Tiago Redaelli
  • 422
  • 4
  • 11
-3
votes
2 answers

Adding a value to a sorted array in Java 8

You are provided the following list that contains (semi-random) years from modern history. Save the list to a text file named “events.txt” Write a program that: Reads in the file “events.txt” Sorts it with the latest events first Determines…
nate k
  • 1
-3
votes
2 answers

Python DefaultDict Ordering Multiple Values Issue

I am trying to order all of the scores in order of each user's score from highest to lowest. I have attempted this with the code below: import collections from collections import defaultdict from operator import itemgetter worker_scores =…
Delbert J. Nava
  • 121
  • 1
  • 9
-3
votes
2 answers

How do I make my list a sorted list?

I am working on an assignment for a programming course I am following and I am using a List to store data. The List class: public List() { init(); } protected Node first, current, last; public int numberOfNodes; public boolean isEmpty()…
-3
votes
1 answer

Python - Writing from a file to another file (Files not identically sorted)

The code below allows me to pass through text files through the function and then output a newly created, third file containing the Username and Password as seen below: File 1 Format(Username) Username:ID:Name:Hash::: File 2…
Eric1989
  • 509
  • 3
  • 6
  • 15
-3
votes
1 answer

Unpack an array filled with lists

I started with something like this: [a,b,s,d] [k,e,f,s,d] [o,w,g] Then I wanted to rearrange them by length in descending order so that I get this: [k,e,f,s,d] [a,b,s,d] [o,w,g] However, to do that, I appended each of those into an array as…
Student J
  • 183
  • 1
  • 3
  • 13
-3
votes
4 answers

Python, sorted(): Sorting football stats by 3rd column

I have football stats that are in a file. I can split the name of the player and each stat by two or more spaces. I am trying to get yards leaders so I need to sort by the 4th column or 3rd index. Here's my code: import re, sys try: file =…
-4
votes
3 answers

Find the number unsorted

Find the unsorted/misplaced number There is a sorted array (say: [1, 2, 3, 4, 5, 6, 7]). Now, some number (say: -2) is inserted "by mistake" (say: [1, 2, 3, 4, -2, 5, 6, 7]). How would one got about finding such misplaced number?
-5
votes
1 answer

How to convert words inputs to a list

I need this for my homework. I'm trying to create a a program where I ask the user for some words. I want those words to be on a list so then I can use .index to call some. I tried to use .set or sorted(set()). It worked with numbers but not words. …
-5
votes
1 answer

why doesn't my sorted code work in c?

Here is my code. it doesn't work: void insertioon (int d) // this part, insert and sort list { struct node *np, *temp, *prev; int found; np=malloc(sizeof(struct node)); np->data = d; np->nextPtr = NULL; …
-7
votes
2 answers

C# sort a string array

I need to sort a string array like below. SG10.01,"SG1 ANTA H 2300 MHz Mod",#.##," dB",LIM,23.00,34.00 GEN_FREQ,2300e6,,MESSAGE,"Action: Connect the external PM power sensor to ANT A via N->7/16…
WENGHui
  • 11
-8
votes
2 answers

how to merge two sorted linked lists in python

i tried so many algorithms to merge the linked lists... def merge_lists(head1,head2): if head1 is None and head2 is None: return None elif head1 is None: return head2 elif head2 is None: return head1 if…
srik sri
  • 53
  • 1
  • 1
  • 8
1 2 3
19
20