C++ :: Delete Smallest Part Of List Of Integers To Sort In Non Decreasing Order

Mar 24, 2013

I am supposed to make a program that take a list of integers from the user and to delete the smallest part of it in order to make it sorted in non decreasing order ..

example : input : 1 2 3 4 5 8 7 6 7 8 9
output : 1 2 3 4 5 6 7 8 9 ( delete : 8 7 )

I need a code that use a technique similar to the merge function to achieve linear time ..

this code works but it is in quadratic time :

int main () {
cout<<"Enter a list of numnbers ending with the sentinel -999:"<<endl;
int A[1000];
int n = 0;
int x;
cin>>x;
while(x!=-999)

[Code] ....

View 4 Replies


ADVERTISEMENT

C++ :: Selection Sort For Non Decreasing Order Input?

Feb 17, 2013

Question: What is the efficiency and big O of the selection sort algorithm when the input happens to already be in nondecreasing order?

Answer: Not sure... since the input is in nondecreasing order, such that example 0, 1, 1, 2, 3, 4, 4, 5 then there will be no swap, Just comparisons of emelemts. So it is big O of n

View 2 Replies View Related

C++ :: How To Sort Integers In A Stack In Ascending Order

Jul 27, 2014

I am pretty much new in C++ programming and i have to do stack exercises. Writing a simple code of sorting the elements in ascending order in a stack.

View 6 Replies View Related

C++ :: Linked List - How To Sort Nodes In Ascending Order

Apr 18, 2013

At the line number 65 that's my sort method first i sum up all the value in the nodes after that i want to sort the Nodes In ascending order but the method is not working ...

#include <iostream>
#include <conio.h>
using namespace std;
// Node Class

[Code] ....

View 3 Replies View Related

C/C++ :: How To Delete Part Of The String

Nov 26, 2012

I have the following string: "type computer {dell}"

And I want to remove the {dell}

So that the output on the screen type computer

Or delete any clause between the two brackets {}

How do i do that ?

View 5 Replies View Related

C :: Radix Sort Function To Sort Array Of 64 Bit Unsigned Integers

Aug 19, 2013

Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.

Code:
typedef unsigned long long UI64;
typedef unsigned long long *PUI64;
PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) {
size_t mIndex[8][256] = {0};
/* index matrix */
PUI64 pDst, pSrc, pTmp;
size_t i,j,m,n;
UI64 u;

[Code]....

View 9 Replies View Related

C++ :: Input Three Integers From Keyboard - Print Smallest And Largest Numbers

Nov 18, 2013

I am trying to Write a program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers. How do i go about it. What i dont know is how to come up with smallest and largest number .

View 1 Replies View Related

C :: List - Why Delete Function Doesn't Delete

Dec 9, 2014

I have to manage a Clinic. I need to delete a booking (for example, if John said he's coming on March 22nd at 15:30 but then he say he's not going to come, I have to delete that booking so another person can use it).

idSearched: the id of the person that is not going to come. I have a lot of specialties and each one has a list. So I ask for the speciality to delete the node (the node contains John's booking). If I don't find it, I return (-1). searchSpecByID return a pointer to the list where the speciality is. So head will point to the first node of the list. In nodeToDelete I have the node I want to delete.

The program detects OK when is the first in the list and when not, but it doesn't delete the node.

Code:

typedef struct bookingList{
tSpecialty specialty;
struct nodo* intro;
} tList;

[Code].....

View 7 Replies View Related

C# :: Sort In Ascending Order?

Mar 10, 2015

i have a list

ID | Location | Quantity
1 | 2 | 5
2 | 3 | 10
3 | 4 | 8

i want the order to be in ascending order by Quantity so it should produce this

ID | Location | Quantity
1 | 2 | 5
3 | 4 | 8
2 | 3 | 10

View 4 Replies View Related

C :: Sort Matrix Such That It Has Value In Ascending Order

Sep 29, 2013

Trying to sort matrix such that it has value in ascending order.

But outcome is coming :

Code:
Matrix after sorting :
2,2,2,2,
2,2,2,2,
2,2,2,2,
2,2,2,2,
Can't find whats wrong.

[Code]....

View 2 Replies View Related

C :: Sort Numbers In Order In Programming

Feb 19, 2014

Write a program that orders three double numbers by increasing value. The program should include a function named sort3 that takes three double * arguments (pointer to double). The function prototype is void sort3(double *x, double *y, double *z); The function should reorder the values pointed to by its arguments so that after the call sort3(&x, &y, &z); the numbers satisfy . Your program should input data and print results using the following format:

Enter three numbers: 4.7 1.4 3.2
The ordered sequence is: 1.4 3.2 4.7

And here is my program: C code - 32 lines - codepad

I am getting a lot of errors when I run it through GCC. I can only use pointers.

View 4 Replies View Related

C++ :: Bubble Sort - Put In Descending Order

Jan 22, 2014

so my program reads a file type which looks like this...

Michelle 71
Marcie 99
David 42
Rebecca 83
Jonathan 79
Matthew 77
Rose 7
Melanie 75
Kimberly 73
Roger 74
Scott 76
Bradley 77
Drextell 10
Heidi 70
Alan 68
Pearl 13
Jeanne 43
Heber 55

Here is whats in the header of the class

class StudentStat {
private:
int Size;

[Code].....

So as of right now the names are stored in a Names string array and the scores are saved in a Score int array. So my question is where do I begin with my bubble sort? I need it to put the scores in descending order so from greatest score to lowest but I need the Names in the string array to still be connected to the number from the list. Never done a bubble sort before so not sure where to begin.

View 1 Replies View Related

C :: Insertion Sort In Ascending Order Not Working

Jun 20, 2014

I am having trouble sorting out a list of names in c. I have code for sorting the names, but when I go to print them out they still are in the same order as they were at the beginning so something isnt right. So the function that I need is the sort_data function.

Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_STRING_LEN 25
void insert_data(char **strings, const char* filename, int size);
void allocate(char ***strings, int size);

[Code] ....

The list that I am reading in is as follows:

matt
susan
mark
david
aden
phil
erik
john
caden
mycah

So I need to get this list in alphabetical order, but when I run my code and print out this list after I run the sort function, they are still in this order.

View 5 Replies View Related

C :: Bubble Sort - Output In Descending Order

Feb 1, 2014

I'm stuck again on a homework problem. I enter 9 8 7 6 5 4 3 2 1 in to the program when it asks me to. I print out the array (just before the bubble sort routine) and I get the numbers in descending order just as expected. So going into bubble sort routine, the numbers are correct.

I should get 1 2 3 4 5 6 7 8 9 as output.

But I get 1 2 3 4 4 5 6 7 8

Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int max_size = 20; // max size of array of numbers
int numbers[max_size]; // array for numbers

[Code] .....

View 4 Replies View Related

C :: Sort Array And Save New Order Of Elements

Sep 25, 2014

So I try to sort an array with qsort and then save the new order, so this means if I have a list like:

4 3 7 2
[0] [1] [2] [3],

after sorting it becomes:

2 3 4 7
[3] [1] [0] [2] <== this is what I want to have!

Code:

void qsort_my(int *a, int l, int r, int *array_order) {
int j;
if( l < r ) {
j = split( a, l, r, array_order);
qsort_my( a, l, j-1, array_order);
qsort_my( a, j+1, r, array_order);

[Code]...

But my problem is that the list gets sorted, but the indexes do strange stuff. When I run with this list:

4 8 14 1 2 1 22 12 2 14
Pos: 0 1 2 3 4 5 6 7 8 9

I get:

1 1 2 2 4 8 12 14 14 22
Pos: 1 0 1 0 0 5 7 6 5 6

And with some printfs I noticed, the first two calls of split it is fine but then strange things start to happen, what I do wrong?

View 6 Replies View Related

C++ :: Read In A TXT File And Sort It By SSN In Ascending Order

Jan 25, 2014

So I need to read in a .txt file and sort it by SSN in ascending order. How to start this but here's what I have so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct Information {
char name[25];
long SSN;

[Code] .....

Also here is the contents of the .txt file:

Matthews,Jocob
459237148
19
3930 4th Blvd, Yourcity, NJ 88710
......
and so on.

View 1 Replies View Related

C++ :: Trace Bubble Sort Using Integers

Mar 6, 2014

Trace the bubble sort using the following integers,which represent the elements in an array.

5,7,3,8,6,7,3

View 1 Replies View Related

C++ :: Merge Sort Destructor - Using Delete On All Pointers On Stack

Apr 7, 2014

How can I use "delete[]" on all pointers on the stack, using a mixture of top and pop functions or variables

View 2 Replies View Related

C++ :: How To Sort And Print Out Object By Surname In Alphabetical Order

Oct 2, 2013

A link list problem, i need some how to sort and print out an object by surname in alphabetical order.

i have a try to do that by this code not working for swamping i should i go about that?
May another way of swapping using pointer instead?

void functions::printdata() {
for(node* temp1=head;temp1!=NULL;temp1=temp1->next) {
for(node* temp2=head;temp2!=NULL;temp2=temp2->next) {

[Code]...

View 1 Replies View Related

C :: Write Program To Sort 2 Ints On Ascending / Descending Order?

Jan 24, 2014

I'm trying to write a program to sort 2 ints on ascending/descending order, using function pointers. here is my code so far:

Code:
#include <stdio.h>
#include <stdlib.h>
int min_el(int a,int b);

[code]....

View 6 Replies View Related

C++ :: Enter Number Or Letter And Sort In Ascending Or Descending Order

Jan 8, 2013

Assignment:

1. Choose what to enter NUMBER or LETTER.
2. Choose type of sorting ASCENDING or DESCENDING.

#include<iostream.h>
#include<conio.h>
main() {
int x,y,z;
cout<<"choose Number or letter
1.number
2.Letter";

[Code] ....

View 9 Replies View Related

C/C++ :: Array To Sort Strings In Alphabetic Order And Read From Stdin

Mar 20, 2014

I have a pre-declared array which sorts strings to it's alphabetic order and want to change it so it reads from stdin.

char *array[] = {"aaa", "ccc", "bbb", "ddd"}

I tried doing something like this:

for (i = 0; i < length; i++)
scanf("%s", &array[i]);

I just can't bring it to work. Another thing is, the input is a a bunch of strings separated by commas and ends with a period. Since I have to make a working C model which gets translated to assembly language later on I can't use functions like strtok.

View 6 Replies View Related

C++ :: Sorting Array Of Numbers Into Ascending Order - Bubble Sort Keeps Crashing

Oct 29, 2014

I am trying to write a program which will sort an array of numbers into ascending order, here is my code

#include<iostream>
#include<cmath>
using namespace std;
int main(){
int array[]={1, 5, 17, 3, 75, 4, 4, 23, 5, 12, 34, 34, 805, 345, 435, 234, 6, 47, 4, 9, 0, 56, 32, 78};

[Code] .....

This compiles fine but when I run the .exe for the first time an error message comes up saying program has stopped working. If I run the program again without recompiling it seems to work as expected.

View 2 Replies View Related

Visual C++ :: Writing A Function That Sort Elements Of Array In Numerical Order?

Oct 17, 2014

I have to write a function called sortMe that sorts the elements of an array in numerical order from highest to lowest values (descending order) or vice versa (ascending order).

The assignment asks to: NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes.

Header of the function sortMe must be as shown below:

void sortMe(int array[],int sortedIndexes [], int size, char mode)

When mode is 'a', the function sorts the array in the ascending order, and when mode is 'd', the function sorts it in the descending order.

Declare and initialize the array array.

Declare the array sortedIndexes but do not initialize it. You are going to play with the array sortedIndexes in the function sortMe.

EXAMPLE:

int array[5]={3, 5,-1,10,0};
int sortedIndexes[5];
sortMe(array,sortedIndexes, 5, 'a');

After the function call, the elements of the array sortedIndexes should be: 2,4,0,1,3.

notice that the function does not e-arrange the elements in the array.

Code:
#include <iostream>
using namespace std;
void sortMe(int[], int, char);
void main() {
int arr[6] = { 14, -5, 5, 0, 22, -99 };

[code]...

how to use the other array.

View 5 Replies View Related

C++ :: Sorting Randomized Array Of Integers Using Bubble Sort Algorithm?

Jun 26, 2013

This program is sorting a randomized array of integers using the bubblesort algorithm.

I am trying to modify n correct the source code,so that the swapping of two values will be done by a function called swap values() by using call-by-reference but function should have as arguments only the two array elements that must be exchanged. (Note: do not pass the whole array to the function!) .We consider an array with the first element containing the number of elements in the array, followed by 10 randomly initialized integers (elements).

The code must sort the 10 elements in ascending order.

Compile: g++ -Wall sorting.cpp -o sorting
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
const int SIZE=10;

[Code] .....

View 1 Replies View Related

C++ :: Sort Players In Descending Order On The Basis Of Score - Program Not Working Properly

Feb 11, 2015

#include <iostream.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

class Player {
private:
char name[20];
int score;

[Code] .....

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved