C++ :: Linked List BubbleSort - Number Of Elements

Apr 22, 2013

Why isn't this bubble sort working?

void LList :: bubbleSort (LList A, int n){
Node *temp;
temp = Head;
int hold;
for (int pass = 1; pass <= n-1; pass++) // number of passes needed for bubblesort is the number of elements-1 {
for (int c = 0; c < n-pass; c++)//only runs for unsorted elements

[Code] ....

It is passed the LList, and the number of items in the list...

View 6 Replies


ADVERTISEMENT

C :: Enter Number Of Elements In Linked List

Aug 15, 2014

Code:
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;

[Code] .....

View 2 Replies View Related

C++ :: Creating A Linked List Of Common Elements From Two Other Linked Lists

Apr 29, 2013

I'm trying to write a function that takes two linked lists and creates a third one with only the common elements.

It assumes the first list (the caller) has no dups, but it doesn't seem to be working. The program doesn't crash, it just hangs when it is supposed to display L3 (the third list)..everything else runs and is displayed fine.

template <typename T>
LList <T> LList <T>:: common (LList <T> &B)//common fct
{
Node <T> *hunter1 = Head;

[Code]......

View 10 Replies View Related

C++ :: Displaying All Elements In Linked List

Aug 31, 2013

#include<stdio.h>
#include<iostream.h>
struct node {
int info;
struct node *next;

[Code] ....

I am getting runtime error in some cases. Sometimes the last input is printed. How to correct the code and display all elements in the linked list.

View 6 Replies View Related

C++ :: Singly And Doubly Linked List - Order Inserted Elements According To Certain Pattern

Sep 13, 2014

I need to make singly and doubly linked list classes that can insert elements. Once the lists are created, I need to order the linked list elements according to a certain pattern.

order2 pattern:
input: 0 1 2 3 4 5 6 7
output: 1 0 3 2 5 4 7 6

order3 pattern:
input: 0 1 2 3 4 5 6 7 8 9 10 11
output: 2 1 0 5 4 3 8 7 6 11 10 9

sequence order pattern:
input: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
output: 1 0 4 3 2 8 7 6 5 13 12 11 10 9

reverse pattern:
input: 0 1 2 3 4 5 6 7 8 9
output: 9 8 7 6 5 4 3 2 1 0

My instructor has given the description of the required classes in a file interfaces01.h as:

#pragma once
#include <cstdlib>
struct ISingleNode {
ISingleNode() {}
virtual ~ISingleNode() {}
virtual void setValue(int value) = 0;
virtual int getValue() = 0;

[Code] ....

However when I am compiling these files in vs 2013 I am getting the error: cannot open include file Singlenode.h,Singlelist.h.

Also I am not too sure about the sorting and reverse logic. How can I implement these logics.

View 1 Replies View Related

C++ :: Returning The Number Of Elements In A List

Jul 24, 2014

I am given an array with n elements but need to write a function where it returns n-1 elements. Do I need a loop for this? Or must I write a prototype...

Here is what I have thus far:

//given array with 5 elements function must return value 4 elements since -1 is a special character length of list is finite

#include <iostream>
using namespace std;
int main () {
int array [] = {1, 4, -1, 3, 2};
cout << "The array has " <<sizeof (array)/ sizeof (int)<< " elements"<< endl;
return 0;
}

View 5 Replies View Related

C :: Add Number In Singly Linked List?

Oct 19, 2014

add number in a singly linked list? here is my code...

Code:
#include<stdio.h>
#include<stdlib.h>
struct node {

[Code].....

View 2 Replies View Related

C/C++ :: Bubblesort In Ascending Order?

Apr 21, 2014

I am trying to build a c++ that reads user input and arrange letters in ascending order. for example, if the user input: Hello my name is Moe! the output will be: !aeeehillmmmnoos (ascending order)

my problem is that when i input hello my name is moe the output will be ehllo (not completing other letters) also when i change class size to 50, it outputs unknown weird letters.

This is my code:

#define CLASS_SIZE 10
#include <stdio.h>
#include <iostream>

[Code].....

View 2 Replies View Related

C :: Insert Linked List Into Another Linked List

Jun 29, 2013

I have a linked list comprised of chars like so...

Code:

node1 - "p"
node2 - "o"
node3 - "p"

I need a function that will take in three perameters...node *replaceChar(node *head, char key, char *str)Stipulations of this function. head is the head of the list, 'key' and 'str' are guaranteed to contain alphanumeric characters only (A-Z, a-z, and 0-9). str can range from 1 to 1023 characters (inclusively). So if I call this function with these perameters..

Code:

node *head == /*the head of the list to be examined*/
char key == "p"char *str == "dog"The new list will look like this...
node1 - 'd'
node2 - 'o'
node3 - 'g'
node4 - 'o'
node5 - 'd'
node6 - 'o'
node7 - 'g'

All instances of 'p' were replaced with 'dog' I have a toString function which takes in a string and converts it to a linked list and returns the head. So assume that you can call the function on str = "dog" so...

Code:

toString(str) == /*this will return the head to the list made from the str*/

If it's unclear what my question is...I am stumped on how to write the replaceChar function the one that takes in three perameters..

View 3 Replies View Related

C/C++ :: Using Linked Lists To Swap Two Adjacent Elements

Jan 6, 2015

I am reading a book currently on data structures in c++. The questions I have is how I would be able to swap two adjacent elements by adjusting only the links (not the data) using, a) singly linked lists, doubly linked lists.

For the single linked list which I am somewhat familiar with (by the content of the book), I would consider taking the Node A, and copying its data into a new Node temp, then re-routing the pointer from whatever connected to Node A, now to Node temp. now I want to re-route the pointer of Node B to Node temp and Node temp to whatever Node was being connected from Node B. Is this the correct approach?

View 1 Replies View Related

C :: Linked List / Adding Element To Beginning Of List

Dec 31, 2014

Code:

// Write a function called insertEntry() to insert a new entry into a linked list.

Have the procedure take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in this chapter), and a pointer to an element in the list after which the new entry is to be inserted.

// The function dveloped in exercise 2 only inserts an element after an existing element in the list, thereby prenting you from inserting a new entry at the front of the list.

(Hint: Think about setting up a special structure to point to the beginning of the list.)

#include <stdio.h
struct entry1 {
int value;
struct entry1 *next;
};

[code]...

This is a working version of the exercise, but I don't think I'm doing what's asked. I was able to add an element to the beginning of the list using an if statement, not creating a special structure that points to the beginning of the list. How would I go about creating a special structure that points to the beginning of the list to add a new element at the beginning of the list?

View 8 Replies View Related

C++ :: How To Access Elements In A List

Oct 18, 2013

I've been looking through containers in the reference section and I can't figure out how to access (i.e. READ) elements in a list...

View 2 Replies View Related

C++ :: Counting Of Elements In A List Of Lists

May 1, 2013

I have a problem like this: I do not know how to count the number of elements in a list of lists. I have the following list of list.

#define VAR(V, init) __typeof(init) V=(init)
#define FOR_EACH(I,C) for(VAR(I, (C).begin()), ite = (C).end();
(I) != ite;
++(I))

std::vector<std::vector<GLdouble> > contours;

[Code] ....

I do not know how to write the part indicated in Bold that represents the number of elements of contour. As seen from the code used for the tesselation OpenGL.

View 3 Replies View Related

C++ :: Watch Elements Of A List In Debugger?

May 11, 2014

How can i look into the element that are pushed into the list. Something like listPointer[0].heapPointer,50

class CA{
public:
CA(void);

[Code].....

View 3 Replies View Related

C Sharp :: Using List Elements As Variable In Query

Aug 27, 2014

I am trying to query an Informix database using a List<T> collection's elements as variables. I can build the list and connect to the database, but I am unsure how to iterate through the list and query the database for each item in the collection.

My list is of type string, and contains Order Numbers. I want to query item information for each order number in the list.

View 1 Replies View Related

Visual C++ :: Template - Adding Elements To List

Jun 9, 2013

I'm doing a homework aasignment on templates, and i have to build a list. The problem starts when i am trying to add elements to the list. For instance if i chose to add 5 different elements (1,2,3,4,5) the output will be (5,5,5,5,5).

Code:
void add_back(T t){
Node* tmp = new Node;
tmp -> m_data = &t;
if(m_head == NULL) {

[Code] ....

View 4 Replies View Related

C++ :: Linked List Delete List?

May 30, 2013

I'm working on a linked list and was wondering how this looks to everybody else for a deleteList function.

void deleteList(Node* head)
{
Node* iterator = head;
while (iterator != 0)

[code].....

View 6 Replies View Related

C++ :: How To Get Number Of Elements Of Multidimensional Wstring

Jul 26, 2014

How to get the number of elements of a multi-dimensional wstring?

The usual char array way not working.

Code:

int main()
{
wstring wstr[][255] =
{
L"bbbb",
L"bbbb",
L"aaa",
L"ccccccc"
};
int Size = wstr.size() / wstr[0].length();
}

View 11 Replies View Related

C :: Check Number Of Elements In Array

Apr 7, 2014

I can have at most 3 structs in array, but it could be 0,1,2 or 3 structs in array. I am trying to avoid dynamic memory allocation. I initialize sensors to 3 to reserve space for them in memory, since there may be at most 3 elements in the array. But I am testing a condition where there will only be 2 elements:

Code:

#include <stdio.h>#include <stdlib.h>
#include <string.h>
typedef struct {
unsigned long long int address;
float current;
unsigned char pressure_units;
} sensor;

[Code]...

The problem is even though there are only 2 sensors out of 3 in the array, sizeof(sensors)/sizeof(sensors[0]) returns 3. I assume because when it allocates memory for 3, it includes that allocated memory even though it really doesn't contain the struct. How can I figure out how many elements were really inserted into array, not just allocated to array?

View 3 Replies View Related

C/C++ :: Array In Class Without Number Of Elements

Apr 10, 2014

Is it possible to have array in class without number of elements, for example: I have a class called Plane with number of motors, and string array of passengers, but I don't have a number of passengers, but then again I have it in constructor, so can i print the list of passengers without having the number as part of the class.

Class Plane
{
private:
int motors; //number of motors

[Code].....

View 8 Replies View Related

C :: Assigning Array With A Variable Number Of Elements

Jul 18, 2014

I have a simple problem about memory allocation.In the function Nr_elements() i assign a value which represent the elements of array. The pointer p is initialised with the address of variable n, but when i compile i dont know why but dont work. This function return a pointer.

Code:
#include<stdio.h>
#include<stdlib.h>
int *Nr_elements();
int *allocate(int);
void deallocate(int *);
[code]....

View 3 Replies View Related

C++ ::  Selecting Arrays With Maximum Number Of Elements

Sep 10, 2013

Supposing you have a 3 or more overlapping arrays (arrays having elements in common), and you wish to select 2 or more of the arrays with the maximum number of elements but less overlap as compared to the rest of the overlapping arrays.

Eg. A[4],B[6],C[5]. A+B contains 10 elements but say the overlapping element is 3, meaning it has 7 unique element.

Also B+C=11 elements , but supposing it has 5 overlaps, it would mean it has only 6 unique elements. A+B+C=15. Supposing the overlaps are 11 then it means the unique elements are 4. Ect. So per the example, the best array options with most unique element would be A+B .

View 4 Replies View Related

C/C++ :: How To Find The Number Of Elements In Main Function

Jun 14, 2014

I have a function where i declared the number of elements in a vector alocated dynamically which returns the vector to the main function. The problem is how can i find the number of elements in main function? I tried length = sizeof(a) / sizeof(int) which gives me the same value, the value of the first element. Here's the code:

int* functie2 (void)
{
int* p;
int c,i;
printf("number of elements: ");
scanf("%d",&c);

[Code]...

I know i could first read the value of c in main and then pass it thorugh parameter, but how can i do it the other way arround?I could also send the value of c allocating one more int value to the vector, but i don't want doing so.

Where's the edit button?

View 4 Replies View Related

C/C++ :: For Given 2D Array Count Number Of Positive Elements In Each Row Sum

Nov 20, 2012

#include <iostream>
using namespace std;
int main() {
    int h;
    double A[10][10];

[Code] .....

View 4 Replies View Related

C/C++ :: Insert Number Of Elements From One Into Another Vector Without Resizing

Dec 28, 2012

I think std::copy appears to do what I'm looking for.

I'm in need of a vector member function that would allow me to "insert" a number of elements from one vector into another vector without resizing or destroying either.

An example of what I'm wanting to do is assign the contents of two[3-5][50-54] to one[7-9][2-6]. Other than looping through both vectors using .at(), is there a way to copy this?

This would be continuous within a user controlled loop with differing elements being exchanged.

typedef vector<vector<unsigned char> > vec;  
vec one(10, vector<unsigned char>(10, '1')),
    two(90, vector<unsigned char>(90, '2'));  

View 4 Replies View Related

C :: How To Find Number Of Elements In Single Line Of Dat File

Oct 30, 2013

How would i get the total amount of elements From the input file(The .dat file) and then store them in a variable?Here is an example to show you what i want. If a line on the .dat file looked like this

1 2 3 4 5 6 7

How would i find the total number of elements? For example the total number of elements in this line would be 7.

View 9 Replies View Related







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