C :: Simple Program To Bubble Sort Values Of A Linked List

Nov 30, 2013

HelI have been tasked with creating a program which (1) takes in integer values from a user (until the user enters -1) and inputs these values into a linked list. This (2)original list is then to be printed out. The program then uses the algorithm "bubble sort" to (3)order the list in descending order before finally printing it out again.

I have managed to do this but I kind of cheated since I do not quite understand how to manipulate a linked list. What did was I took the values in the linked list and transferred them into an array and then did bubble sort on that array.how to do bubble sort on a linked list as well as how to print a linked list.

Code:

#include<stdio.h>#include<stdlib.h>
typedef struct node
{
int info;
struct node *link;

}Node, *NodePointer;
void printList (NodePointer head)
}

[code]...

View 4 Replies


ADVERTISEMENT

C++ :: Applying Bubble Sort On Linked List

Feb 27, 2015

I'm trying to apply a bubble sort on a linked list. It works in the first traversal, but then after the code cPtr = nPtr;, it inputs repeated digits at the end of the (semi-sorted) linked lists.

View 1 Replies View Related

C++ :: Sort Function For Linked List Program?

Oct 7, 2013

I'm having trouble getting my sort function to work,

void Linkedlist::sort(int num)
{
node *q;
node *a;
int input=num;

[Code].....

I get a crash and I've narrowed it down to the last if statement. Also this function is meant to handle new members after 1 member has been added.

View 7 Replies View Related

C++ :: Program To Implement Bubble Sort

Feb 15, 2015

Design a C++ Program to implement the following functions:

a.)the function for bubble sorting : int bubblesort(int*a,int size).
b.)the function for merge sorting : int mergesort(int*a,int size).
c.)the function for generating array of random elements: int generate(int*a,int size) which calls the function rand() in c++.
d.)Test both bubble sorting and merge sorting with 10,100,1000,10000,100000 and 1000000,4000000 integers.

The integers are from the array generated by part c).calculate the time spent in calling each sorting.you may use a function in <time.h>to get the current time. Draw curves to compare the speed performance between the two functions. The merge sorting algorithm implementation must use recursion. you are expected to define a global array for holding result from merging two arrays.otherwise,it may cause a lot extra money in recursion.

Hint 1:use the following format to calculate the time cost for bubble sort.

{……..
Time1=Get the current time(call a function in <time.h>);
Bbblesort(….)
Tme2=Get the current time(call a function in <time.h>);
Time_cost=the difference between time 1 and tim2;
…….
}
Print your program and test results

View 1 Replies View Related

C/C++ :: Bubble Sort Two Arrays Program

Apr 15, 2015

Been working on this program for a while. It's currently broken in several parts but it at least reads and stores the data into the arrays correctly. The problem is writing the sort function and the swap function. The other problem is writing both of these to keep the correct ages with the correct names.

/*
Write a program to allow the user to enter up to ten people with their age.
The names will be a full name consisting of a last, possibly a middle initial, and a first name.
The full name will be no longer than 40 characters in length.
The full will be stored in an array of strings, a two dimensioned array of characters.
The ages will be stored in an array of integers. Manage the arrays as parallel arrays.
Data entry will be from the keyboard and will read the full name followed by the age.
Data entry will terminate when the arrays are full or when nothing is entered for the full name.
Use a subroutine to enter the data and pass the arrays to the subroutine, do not use global arrays.
Once the data is completely entered, use another subroutine to print out the arrays to the screen.
Then use a subroutine to sort the data on the full names, ascending order.
Reuse the print subroutine and print the sorted data out to the screen.
Write another subroutine which sorts the data on age as the primary sort and full name as the secondary sort.
Finally reuse the print subroutine to print the data to the screen.
The main program will call the data entry function, followed by the print function, the name sort function, the print
function, the age sort function and finally the print function.
All data will be passed to the functions, no global data.
*/

#include <stdio.h>
#include <string.h>
#include <stdio.h>
#define SIZE 5

void input(char fullname[][25], int age[]);
void output(char fullname[][25], int age[]);

[Code] ....

View 14 Replies View Related

C++ :: Bubble Sorting Linked List That Creates 100 Random Integers?

Feb 1, 2015

I am relatively new to C++ and am trying to bubble sort my linked list that creates 100 random integers. Everything works, but I am unsure how to continue this to include a bubble sorting method.

#include "stdafx.h"
#include <iostream>
using namespace std;
class Node{
public:
int data; //set data

[Code] ....

View 1 Replies View Related

C++ :: Import A File Containing Words And Numbers To Linked List - Bubble Sorting

Feb 16, 2013

I have a code able to import a file containing words and numbers to a linked list, but I also need to sort this linked list alphabetically. I've done research on this involving bubble sorting, but no explanationcan achieve this objective.

Below is the code that can only put the file into linked list:

Code:
#include<iostream>
#include<conio.h>
#include"U:C++WordClass2WordClass2WordClass.cpp"
#include<fstream>
#include<vector>
#include<string>
using namespace std;

[Code] .....

View 5 Replies View Related

C :: Simplifying A Simple Linked List With Search Function

Jun 5, 2013

Code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

struct node
{
int data;
struct node *next;

[Code] ....

It fills the singly-linked list with 0 through 9 and calls a function to prompt the user to search for a number. I don't see any glaring errors, I was just wondering what could be done to simplify it or if there's anything I missed.

View 8 Replies View Related

C++ :: Linked List Sort By Age

Mar 22, 2013

I know how to add a node and delete a node from the beginning and from the end of the List. Now I want to sort the List by Age. I tried everything but there must be a very little mistake that I can't find. Here is my code:

#include <iostream>
using namespace std;
struct Node {
char name[20];
int age;
double height;

[Code] ....

View 13 Replies View Related

C++ :: Quick Sort Using Linked List?

Feb 23, 2013

I've been trying to implement a quick sort algorithm for linked list but when i try to run it with 1000000 values my compiler tells me its running too long and ends up not finishing. However when i run it with 10 values it seems to work fine.

Is there anyway to improve this run time?

Code: struct listnode *quicksort( struct listnode *data ) {
size_t length = 0;
struct listnode *pivNode, *temp = NULL, *low = NULL, *high = NULL, *ltail = NULL, *htail = NULL, *prev = NULL, *end = NULL, *next;
// Get length
for( struct listnode *cursor = data; cursor != NULL; cursor = cursor->next ) {
length++;
}

[code].....

View 2 Replies View Related

C :: Merge - Array Sort On Linked List

Oct 15, 2014

This is in response to the bubble sort and selection sorts for linked lists. On my system, (Intel 2600K, 3.4ghz), it sorts a list with 4,194,304 nodes containing 64 bit unsigned integers in about 1.05 seconds.

Code:
#define NUMLISTS 32
/* number of lists */
typedef unsigned long long UI64;
typedef struct NODE_{
struct NODE_ * next;
UI64 data;

[Code]....

View 6 Replies View Related

C :: Sorting Linked List Using Quick Sort

Mar 4, 2014

I am trying to sort a linked list using quick sort in C. Here is my code--Actually, first I am inserting data in the list from a file. For a small file, it's working fine. But for large file it's just not working.

Code:
struct node {
int data;
struct node *link;
struct node *plink;

[Code] .....

View 1 Replies View Related

C++ :: In Place Merge Sort For Linked List

Oct 3, 2014

This is in-place merge sort, for merge function.

LinkedListNode::LinkedListNode(int value) {
this->next = NULL;
this->value = value;
}
LinkedListNode *mergeSortedLinkedLists(LinkedListNode *firstList, LinkedListNode *secondList)

[Code] ....

View 3 Replies View Related

C++ :: Custom Linked List Sort Method

Apr 3, 2013

I am making a custom linked list (for fun!) and want to implement a sort method that sorts the stored data using the stored types > and < operators (will require the type to have these operators overloaded)

What is the best way to do this? I guess the first thing one might jump to would be to compare the current node with the the node to its "right" see if one is greater than the other. Then keep iterating through the list until you don't swap any more nodes. However I am thinking there is probably a more efficient way to do this. Here is my code so far:

#ifndef LIST_HPP
#define LIST_HPP
#include <string>

[Code].....

Surely there is a way to sort with only one iteration through the list?

View 2 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++ :: Insert Sort Alphabetically Using Doubly Linked List

Mar 16, 2014

is this correct? I used this sorting with numbers i don't know if it is the same with strings. When I run it, there are no errors detected, but when i try to view it, the inputs does not appear.

void add(node **h, node **t){
node *temp, *ptr;
char s[20];
temp = (node*) malloc(sizeof(node));
printf ("-INSERT-");
printf("Fruit: ");
scanf("%s", temp->fruit);

[Code] .....

View 1 Replies View Related

C :: How To Sort Data In Linked List And Arrange Them Highest To Lowest

Aug 12, 2013

i am making a program that reads a file from .txt and print them out using linked list. However, i need to sort them from the highest price to lowest price.

Code:

/* my structs */
typedef struct{
Node *head;
Node *tail;
Node *iterator;
int size;
} List;

[Code]...

i know its long but im afraid that i might miss out some things.

View 12 Replies View Related

C/C++ :: Accept Items In Singly Linked List And Sort Nodes?

Jan 11, 2013

i want to make a program that accepts 15 items in a singly linked and sorts the nodes.

View 1 Replies View Related

C/C++ :: Bubble Sort And Selection Sort?

Feb 19, 2014

You will write a program that uses a multidimensional array having 3 rows and 8 columns and sorts each of the rows using both a bubble sort and a selection sort.

You must declare the array inside of main. You will have a for loop containing the calls to bubbleSort and selectionSort. You need to pass into function bubbleSort and selectionSort the following: 1) each column of the multidimensional array, 2) the size of the column, and 3) a particular row number of the multidimensional array to be used for printing out the "pass" shown on the following pages.

I keep getting an error that the identifier for bubbleSort and selectionSort is not found. (Error C3861) Also, I feel like I'm missing something in int main() to get it to sort properly.

# include <iostream>
using namespace std;
int main()
{

[Code].....

View 14 Replies View Related

C++ :: How To Delete All Values In The Linked List

Feb 15, 2012

I have made this program for linked list, but i have one problem with it. I want to make a function that will delete all same values I inuput in the list.

Example: if user inputs 5 I want to delete all 5 for the list. I have tried doing this with the loop inside regular function that erase single value.

This is function that erases single value:

Code:
void list::Delete (int a) {
node *temp=head;
if (temp==NULL)
return ;
if (temp->getNext()==NULL) {
delete temp;

[code]....

View 3 Replies View Related

C++ :: How To Use Bubble Sort

Feb 20, 2012

how can i use my function now in the main ... after i put the numbers for example i want them to be sorted in ascending or descending order

PHP Code:

# include <iostream>
using namespace std;
int main () {
    int array [10]; 
    cout << " enter numbers : ";
    for ( int i=0; i<10; i++)

[code]....

View 4 Replies View Related

C# :: Linked List Storing String Values

Apr 8, 2015

I am creating a to-do list application and to store the tasks on the list, I am trying to create a linked list. the code for it so far is as follows:

public class Node //Class for nodes which make up a linked list {
//Declaring the data to be stored in each node and next variable to point to the next node
public string title;
public string description;
public string priority;
public string finish;
public string complete;

[Code] ....

The problem with this arises when I try to create a new node from another class like so:

createForm create = new createForm(); //Creates an object reference to createForm
create.ShowDialog(); //Shows the createTask form for creating a new task
//Declares variables and stores the return value of methods in createForm
string _title = create.getTitle;

[Code] ....

The variables _title etc.. all store values from text boxes as string. However, the code creating the object says the the variables cannot be implicitly converted from type 'string' to 'int'. Why this error is happening??

View 3 Replies View Related

C++ :: How To Optimize Bubble Sort

Mar 24, 2013

How to optimize this bubble sort program?

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;
int main() {
long *A;
A = new long[100000000];

[Code]] .....

View 2 Replies View Related

C :: Bubble Sort With Random Numbers

Nov 6, 2014

i'm trying to fill an array with random numbers and then sort them via bubblesort. it seems to work so far. the problem is, that i seem to get the same numbers for the same input. somehow the randomness isn't working.

Code:

#include <stdio.h>
#include <stdlib.h>
int main() {
int a, b, c, d, e, f;
}

[code]....

View 3 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++ :: Sorting Golfers Using Bubble Sort

Oct 29, 2013

I have to sort golfers using bubble sort. Here my code:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
void tellUser();
double calcAvg( int, int, int, int, int &);
void swap( int &num1, int &num2);

[Code] ....

View 2 Replies View Related







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