C :: Concept Of Insertion Sort - Verification
Apr 7, 2014
Can validate if my code implements the concept of insertion sort. The program is executing successfully. Just need a verification!
Code:
int i,j,k,a[100],n,num,min,max,temp;
printf("Enter array size: ");
scanf(" %d",&n);
printf("
Enter the numbers:");
for(i=0;i<n;i++)
scanf(" %d", &a[i]);
[Code] ....
View 9 Replies
ADVERTISEMENT
Apr 29, 2014
I am trying to sort a student database by age,but i am not sure whats wrong i think it has to deal with tmpstudent variable.
Code:
void insertion_sort(StudentDB *db) {
int i;
for (i = 0; i < db->num; ++i) {
int j = i - 1;
int val = db->records[i].age;
[Code] .....
View 1 Replies
View Related
Apr 3, 2014
I want to use two dimensional array by insertion sort or quick sort
View 2 Replies
View Related
Jan 15, 2015
This program I'm working on accepts an array size from the user, prompts the user to store that many integers, sorts them from smallest to largest, and then searches for duplicates with a simple for loop. The ultimate goal of the assignment was to display duplicates in an array, and the rest of the functions are just how I decided to reach that goal.
Anyway, my program crashes if I choose an array size larger than 7. It sorts and displays duplicates perfectly with 7 or fewer arguments.
The exact moment it crashes is after I enter the final value it prompts me for, so it appears my inputsize() function and my inputarray() function are working, and the error may be in the arrsort() function. Code is below:
Code:
#include <stdio.h>
int funcinputsize(int);
void funcinputarray(int [], int size);
void funcarrsort(int [], int size);
void funcdupe(int [], int size);
[Code] ...
View 4 Replies
View Related
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
Apr 11, 2013
I am trying to run this program for Insertion Sort, But some how I am getting some problem:
#include<iostream>
int main(){
int i,j,key,n;
scanf("%d",&n);
int a[n];
[Code] .....
Error
In function 'int main()':
Line 10: error: ISO C++ forbids variable-size array 'a'
compilation terminated due to -Wfatal-errors.
View 2 Replies
View Related
Nov 7, 2013
So I have an insertion sort function implemented that sorts through an array, but I'm having a problem showing the correct number of comparisons to work.
Each time I'm checking a value with another, the counter should update.
For instance, having an array of 10 elements going from 10-1 should give 45 comparisons, but I'm getting 54 comparisons.
void insertionSort(int a[], int& comparisons, const int& numOfElements) {
int j, value;
for (int i = 1; i < numOfElements; i++) {
value = a[i];
for (j = i - 1; j >= 0 && a[j] > value; j--)
[Code] .....
View 3 Replies
View Related
May 4, 2014
This program using the selection, insertion, and bubble sorts. The program needs to be able to do the following:
1. Create an array of 1000 population records when the array object is instantiated. Call it unSorted.
2.Open the file called "Population.csv" (on the portal) and invoke a function that loads the population data into the array.
3.Create a second array of 1000 elements that will be used to sort the data using the different algorithms. Name is sortedArray.
4.Write a function that will copy unSorted into sortedArray and execute that function.
5.Using a function, display the unsorted array.
6.Invoke the insertionSort () function that will sort the sortedArray using the insertion sort algorithm. Sort the population data on the rank field in ascending order. Alternatively, you can sort in descending order on population.
7.Using the display function, display sortedArray.
8.Display the number of iterations it took to do the sort using this algorithm.
9.Repeat steps 4-8 for the selection and bubble sort algorithms.
Here is my code so far:
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void loadArray (int unSorted[], int s);
void displayArray (const int num [], int size);
[Code] .....
Here is a few lines from the Population.csv file contents:
Code:
Alabama,Baldwin County,140415,389
Alabama,Blount County,51024,908
Alabama,Calhoun County,112249,477
Alabama,Colbert County,54984,858
Alabama,Cullman County,77483,653
Alabama,Dale County,49129,927
Alabama,Dallas County,46365,974
Alabama,DeKalb County,64452,753
I'm not sure how to load the data from the file into the array properly, I attempted this. I also don't know how to copy the unSorted into sortedArray.
View 14 Replies
View Related
Jun 7, 2014
this is really important i searched an example code about "Username and Password Validation between Server and Client" through internet a LOT and i couldn't find anything..
View 3 Replies
View Related
Nov 21, 2014
I have an assignment to create a program that will display the duplicate numbers that were entered by a user. I have the code finished and I have covered the basic requirements of the assignment. However, during my testing I found that if I enter anything other than a whole number (i.e. char or float) the program will run out and exit. I would like to add a little code to verify that the user has entered a whole number. I cannot seem to get this to work though. I have written other codes that verify if a number is above and below a certain value, I just do not know how to look for a certain type of entry.Here is my code:
int main() {
int number[20];
int duplicateNumber[20];
int i, j, k, counter = 0;
// Get number input from the user
for (i = 0; i < 20; i++) {
printf("Please enter a whole number %d: ", (i + 1));
[Code]...
View 3 Replies
View Related
Aug 23, 2014
I am trying to build a program that takes a user password (6+ characters, One uppercase, one lower case, and one number), and checks for errors. The idea is that if the user is doing something wrong (say, forgetting to use an uppercase letter), the program will tell them what the error is, and prompt them to enter the program again.
I get through the building process without errors, but whenever I run the program, I get this error: [URL] ....
Here is my code:
#include <iostream>
#include <cctype>
using namespace std;
bool checkPass(char [], int); //Password Checking Function
char convert(string);
[Code] ....
According to the box, the error appears on line 56 and 68.
View 5 Replies
View Related
May 16, 2014
I tried to build a basic username-password verification program; I already have 2 text documents, usr.txt and pass.txt in which username and password are stored. Then have written this program to check the username and password, but every time it says Access Denied.
Here's what I have written:
#include<stdio.h>
#include<conio.h>
void main()
[Code].....
View 6 Replies
View Related
Feb 15, 2013
Write a program using all storage class specifiers?
View 2 Replies
View Related
Dec 31, 2012
I am not getting the real concept of delete operator. If it deallocates the memory, then why i am getting such output..!!
int main() {
int *a , b=5;
a = & b;
cout << *a << endl;
delete a;
cout << *a;
getch();
return 0;
}
Output:
5
5
View 4 Replies
View Related
May 18, 2014
I would like to create program which will analyse bitmap so would need good concept to save data. I am interested about the theory and I realize that i must to think this carefully because bad concept could create insufficient memory or inefficient program. Basically I want my program work with HSV or HSL model so I would need to convert the bitmap to HSL, but I am not sure if I should convert it first and then analyse all pixels or should I start to analyse the bitmap and make the conversion to HSL during it. But my main question is what method to choose to save the data in memory.
Even that I would start with very small, it should work also with bigger image like image having 1200 or even 4200 px on height. So the program should first analyse all columns of pixels in the image so for example 1200x800 px image has 1200 columns. So I would like to know if is it possible to create such object which would have such structure like this
Obj->basicColumnData->black->columns[name]->group
and in the place of columns should be placed data for every column. I would look for groups of pixels in the column, so in the result the column x could bear e.g. 500 groups of information and every group should contain the range of pixels e.g. group 1 should contain y value from 0 to 20, group 2 should contain value from 25-27 and so on. So I would create 1200 columns bear many of groups. This would be contained in "black" or "white" member to contain the data. This is just simplified idea, but the whole object should contain next data not just basicColumnData... So there should be another members bearing information calculated from the selected data.
So my question is what kind of method of saving data use for this? Should I use heap and dynamic allocated memory or should I create custom class, which will define every member, but these members will have to be dynamic memory? With the dynamic memory is there problem that there could be not enough memory to create such big object?
View 5 Replies
View Related
Jun 15, 2013
Well, basically, what I've been doing was creating a class that would implement the concept of Double Linked List, but that would behave like a queue ( the STL implementation is deque, or Double Ended Queue ).
The problem occured when I have been trying to generalize the class using templates. I mean, why use only integers ? Why not double or char or what not ?
Worked perfectly before including all the template stuff..
// Source.cpp <=> Main.cpp
#include <iostream>
#include "DList.h"
using namespace std;
int main(void) {
DList<int> *list;
list = new DList<int>();
[Code] .....
The errors returned by the compiler:
Error1error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6
Error2error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6
View 6 Replies
View Related
Apr 2, 2013
Create an a simple Payroll Management Application using the concept of Binary Tree. The program will allow you to add, sort, view, search record. The application have also the capability to save and retrieve data in a file.
View 1 Replies
View Related
Feb 7, 2014
Here is the most recent failure of trying to insert a text file into an AVL tree. The text file has a word or phrase of each line.
like:
apple
orange
blueberry
cookie
car
hat
This is the function that isn't working.
void fillTree(avl_node *root){
ifstream inp("words.txt");
if(inp){
[Code]....
I know that the getline() can have a deliminator parameter but since there is no commas should I put an newline deliminator? Would that be ? And I know that the insert() function works.
View 5 Replies
View Related
Apr 4, 2015
I am working with A.V.L. trees at the moment and I have to implement a program that inserts a node and if needed re-balance the tree.I have problems when I have to do a double rotation because after I insert a node the tree is messed up. This is a picture with what my program shows after i run it. [URL] .....
void length(NodeT* p,int *maxi,int l) {
if (p!=NULL) {
length(p->left,&*maxi,l+1);
if ((p->left==NULL)&&(p->right==NULL)&&(*maxi<l))
*maxi=l;
length(p->right,&*maxi,l+1);
[Code] .....
View 1 Replies
View Related
Aug 25, 2014
Suppose multiple threads are are trying to insert into a STL Map, both are trying to insert with same key. As per my understanding it will not cause any issue till you invalidate the iterator. Here as per me it will not invalidate the iterator.
View 2 Replies
View Related
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
Mar 4, 2014
I have been working on a program that records the time it takes the user to complete a maze. The user's time is then recorded and inserted into a linked list of structures based on the time (from quickest time to longest). I wrote some code that does this, but I was wondering if I can make the code more concise/make sense -- like only using two pointers or having less if statements.Here is a struct that are the elements of the linked list (I also have a global variable to keep track of the head of the list:
Code:
//stores player's best time.
struct PlayerTime {
char name[MAX_STR_LEN];
float seconds;
struct PlayerTime* next;
[Code]....
View 4 Replies
View Related
Feb 9, 2015
I am unable to insert data in a linked lists. Show function is not working.
insert
Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node *next;
[Code] .....
View 7 Replies
View Related
Feb 18, 2013
I'm trying to create a function that allows insertion anywhere in a linked list...here is what I have so far but am a bit confused on where to go from here
Code:
void llAddAtIndex(LinkedList** ll, char* value, int index) {
LinkedList* newNode = (LinkedList*)malloc(sizeof(ll));
newNode = *ll;
LinkedList* prevNode = (LinkedList*)malloc(sizeof(ll));
[Code].....
View 7 Replies
View Related
Aug 30, 2013
While I know that linked lists seem to be a fairly common problem area among beginner C programmers, most examples that I have come across abstract the sorting of a linked list to a separate function which is sadly not what I am trying to do.
The code below is my attempt to have the nodes inserted into their correct place so that once all nodes have been inserted they are already in a sorted order.
Code:
int main(int argc, char *argv[])
{
struct node_t* dict_head;
struct node_t* traversor;
struct node_t* newnode;
int list_size = 0, insert_key, search_key, delete_key, x;
char insert_word[WORDLEN];
/*Opening the dictionary file provided by the command line argument */
FILE *fp;
fp = fopen(argv[1], "r");
[Code]....
The problem is as follows. When you provide it with input in which the first word scanned is any other word than that which would be placed at the front of the list, it works as intended. For example.
7 world
0 ant
3 kodak
1 best
6 the
2 is
Produces ant -> best->is->kodak->best->world
However, swapping ant and world in the above input gives:
world->best->is->kodak->best->world
In regards to why I have my head node set as a node without a word or a key, it was suggested that I make it so that the first node inserted is set to be the head of the list and then changed as sorting required, yet this caused only additional problems.
View 10 Replies
View Related
Feb 24, 2014
I need to set a parent for each new node being inserted but I can't get to incorporate that into my insert function.
Here's a part of my code:
struct bst_node {
string value;
T key;
bst_node<T> *left;
bst_node<T> *right;
bst_node<T> *parent;
[code].....
View 2 Replies
View Related