C/C++ :: Adding And Deleting From List

Dec 11, 2014

i am writing a program to list the 8 planets, then you select which planet you want. it gives you the mass of the planet, the radius, then you use the mass and radius of the planet to find the surface area(sphere formula) and the density of the planet. along with those options, you have to add and delete a planet from the list and then sort them alphabetically. All i am having trouble with is the adding and deleting part. the code the adding and deleting from the list would go in cases 9 and 10.

heres my code as of this point.

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
void print(const std::string& item) {

[Code] ....

View 3 Replies


ADVERTISEMENT

C++ :: Adding And Deleting From List

Dec 11, 2014

I am writing a program to list the 8 planets, then you select which planet you want. it gives you the mass of the planet, the radius, then you use the mass and radius of the planet to find the surface area (sphere formula) and the density of the planet. Along with those options, you have to add and delete a planet from the list and then sort them alphabetically. All i am having trouble with is the adding and deleting part. The code the adding and deleting from the list would go in cases 9 and 10.

heres my code as of this point.

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
void print(const std::string& item) {

[Code] ....

View 5 Replies View Related

C :: Adding And Deleting Element To A Structure

Feb 10, 2015

Write a program having structure which hold address fields as Name, Address Line 1, City, State, ZIP. Program should able to hold 50 entries of address. Application should have feature/choice option to add, delete and Search address by name .

View 1 Replies View Related

C :: Array Of Structs (adding / Deleting Elements To A File)

Sep 20, 2013

I want to write a program to record my neighborhoods's name and address by using an array of structs and file.

my array of structs is

Code:
#define SIZE 30
typedef struct{
char name[30];
char address[100];
}Detail;
Detail neighbor[SIZE];

And I want to make adding,deleting, and searching functions.Something like

Code:

void add();//Add name and address to a file,
//and add more to the same file if I want to.
void del();//Delete or Change some neighbor's name or address
//in the same file(Can I?)
void search();//Search name and show detail

So I started to code adding function first, but I don't know that I need to use pointer to code each functions relations, and I don't know how to check that my input's already exists yet. But I started some code below...

Code:
void add() {
int i=0;
FILE *fp = fopen("neighborhood.txt", "at");
if ( fp != NULL ) {
do{

[Code]......

View 8 Replies View Related

C# :: Deleting LIST From CSV?

Mar 7, 2014

Basically, I have a LIST that is saved in a CSV file, and I need to remove a particular record after using the search feature (which populates the fields from the CSV file... i.e. ID, Name, etc...).

I am able to get the details that are in the text fields by using a search feature. This is then put in:

logic.remove(tempIndividual)

In class myLogic.cs, then I have this method:

this.individual.Remove(tempIndividual)

Upon debugging, I can see that tempIndividual is populated with the correct data. However, I need to remove this data from the CSV file. Am I on the right track, or totally off? Maybe it is not complete, cause I can't get to the part where it actually removes the data from the CSV, or at least I'm not sure if .Remove is able to do it on its own.

View 9 Replies View Related

C++ :: Deleting Node From End Of A List

May 5, 2013

I'M TRYING TO DELETE FROM THE END OF A LINKLIST...Actually I delete the last node but the problem is that I lost the end of the list, in other words my list leaved of pointing to NULL.I really don't know how to fixed, (it was more easy to delete from head)

Code :

void linkedstack::pop() {
if(head==NULL){
cout<<"The linklist is empty"<<endl;
return;}
else {
node *current=head;

[code]....

View 3 Replies View Related

C++ :: List Pointer Not Deleting?

May 30, 2013

LinkedList* listPtr = new LinkedList;

listPtr->addNode(3);
listPtr->addNode(4);
listPtr->addNode(6);
listPtr->print(std::cout);

delete listPtr;

listPtr->addNode(5);
listPtr->print(std::cout);

When I run the program it outputs
{ 3, 4, 6 }
{ 5 }

Why does the LinkedList object that listPtr is pointing to not get destroyed??

View 8 Replies View Related

C++ :: Deleting A Linked List?

Mar 27, 2014

If I have a linked list, how can I delete it at the end of my program to free the memory taken up. I know I have to use delete but not sure how to use it in this case.

Here is the code that I have:

#include <iostream>
#include <cstdlib>
using namespace std;
struct Numlist {
int num; //Number
Numlist * next; //Pointer to the next node

[code]....

View 4 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 :: Deleting A Node From Linked List

Apr 19, 2013

I have a struct with some select student information. My wish is to be able to have the user type in a surname from the list, and for that entry to be deleted. However I am slipping up for some reason.

Here is the start of my program showing my struct:

Code:
#include <stdio.h>
#include <string.h>
#define NAME_LEN 30
#define LINE_LEN 80
struct record {

[Code] ....

I get the following errors in my while loop as well as the if statement below that loop:

-invalid operands to binary !=
-invalid type of argument '->'

View 7 Replies View Related

C++ ::  linked List - Deleting A Node

Mar 2, 2013

If p is a pointer pointing a node to be deleted, then what's wrong in the following code:

cout << "Do you want to delete this record? (y/n) ";
if (getch() == 'y' || getch() == 'Y'){// Delete record.
if (p == *ph){//If first node is to be deleted.
*ph = (*ph)->next;
delete p;

[Code] .....

View 2 Replies View Related

C++ :: Deleting Nth Node From Doubly Linked List

Sep 19, 2013

I need to delete the Nth node from a doubly linked list. I know I just cant delete it out right. I have all the goodies including a templetized node class. This is the code we're given:

template <typename T>
void doublyLinkedList<T>::deleteKthElement(const int item) {
}

It accepts an int, and should go to the Nth node and delete it.

View 1 Replies View Related

C++ :: Deleting Middle Node In Linked List

May 1, 2013

I am trying to delete a node from the end of a Linked List but I have some problems. Every node has it's unique code. Here is what I do:

1. Ask the user for the unique code of the node.
2. Ask him if he wants to change the data in it or delete the whole node.
3. If he chooses to delete it, I do this:

//let's say that temp1 points to the node
List *temp2 = temp1;
temp1 = temp1->next;
delete temp2;

And it's just not deleting the node.

View 2 Replies View Related

C++ :: Deleting Head Node In Linked List

Sep 8, 2014

I would like my function to return the data that was deleted. I have this code at the moment, where value_type is just an alias for int at the moment:

node::value_type linkedlist::removeFromHead(){
node* temp_head;
node::value_type data;
data = head_ptr->getData();

[Code] .....

When I try to use this function though, I get a segfault.

View 19 Replies View Related

C++ :: Deleting Linked List Nodes Recursively

Jun 25, 2014

I am creating a Linear linked list in c++. I've written all the functions for it, but now I want to try and do them using recursion.

I managed to make functions for adding and displaying nodes on the list, but I am stuck on the function for removing nodes. First I want to try and write a function the removes the last item on the list. But for some reason my code isn't working properly.

Here is the code :

void removeLastItem(node * &head) {
if(!head) {
delete head;
head = NULL;

[Code] ....

NODE - My structure name
NEXT - The pointer to next element.
HEAD - The first (head) pointer.

The couts in the if statements are just for testing. In fact after I Run my program it does as it is supposed - enters the second if /b]case as many times as there are elements and then executes the first [b]if statement. But for some reason it does not delete the actual node.

View 2 Replies View Related

C :: Seg Fault When Adding To List

Apr 3, 2013

I am currently working on a program and Originally I was to create a bash program to extra information from youtube and create a table of users, views, titles, duration, etc. (I sent each to a txt file)..Then I was to create a C program to use the extracted information. In this case Users and read in the conents of user.txt and construct a linked list to hold the information. Then print from the Linked list.I managed to do that,

Code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LINE_LENGTH 100
void build_a_lst(), print_a_line(), print_lst();
void insert_at_end();
}

[code]...

What I have to do now is start reading in The other files and construct a table. And radix sort it by views. But to get to the radix sort part I get stuck on reading in all the files correctly and having the linked list hold them. I keep getting seg faults when I change my code.

View 3 Replies View Related

C# :: Adding To A String List

Feb 25, 2014

So I have this code:

temp =count + " x " + name;
if (count > 0) { Stats.Inventory.Add(temp); }

Where Inventory is declared as

public static List<String> Inventory, Sellables;

and temp and count are declared locally as

double count = 0;
string name = string.Empty,temp = string.Empty;

An it throws an error

>Craft.exe!Craft.Stats.InventoryUpdate(string NewInventory) Line 166 + 0x73 bytesC#

My main questions is why? This is my first time using lists

View 14 Replies View Related

C :: Linked List - Adding Nodes

Jul 23, 2014

I wrote function to add to elements in the list, but when I call printList function it returns me empty list ! I'm new with linked list in C

Output:

Empty list
List is empty add element at the begining
New node with packet num 245
List is not empty add element at the end
New node with packet num 486

Linked list: Empty

Main:

Code:

int main(){
struct node * start ;
start = NULL;
int i;
/*Check if list is empty*/
if(start == NULL){
printf("Empty list

[Code]...

View 2 Replies View Related

C :: Adding To Middle Of Linked List

Feb 17, 2013

I'm trying to make a function that lets me pass an index and a string and will insert the string at that index in the linkedlist..

Code:

typedef struct node {
char* value;
struct node* next;
}

[code].....

View 4 Replies View Related

C++ :: Adding At The Beginning Of Linked List

Aug 18, 2013

I've been struggling with linked list for a few days. I've tried performing a few operations. Here is my code. the add_begin() function doesn't seem to work.

#include<iostream>
using namespace std;
struct node {
int data;
node *next;

[Code] .....

View 8 Replies View Related

C++ :: Linked List Adding Nodes?

Oct 17, 2014

Ok so I am having difficulty adding nodes to my linked list....

how to add a third node while keeping track of the address...Thats where I get lost..I don't know how to keep track of the addresses of the next node..

#include <iostream>
using namespace std;
typedef struct Node{

[Code]......

View 1 Replies View Related

C :: Adding A Second Node To A Doubly Linked List

Mar 6, 2015

I am having trouble adding a second node to a doubly linked list. I define my list as follows:

Code:

typedef struct Node {
char command[256];
int length;
struct Node *prev;
struct Node *next;
} userInput;
}

[code]...

Now, when I iterate back through my list (I want to start at the tail and work my way towards the head), I can only ever get the 1st node to print, then the 2nd node is garbage, which means, to me, that I've linked something wrong.

View 3 Replies View Related

C :: Reading Data From A File And Adding Them To A List

Jun 1, 2014

I've been trying to write my homework assignment (a list of countries, their codes and their capitals) and I've done most of it but I'm stuck at this: I have to open a file, read it and if there are data, add them to the list. So far I've created an element of the structure, queue list, printed the list on the screen and freed the memory. I thought that for reading the file and adding the data I could first open the file (of course) with fopen and after that use a for loop (i=0;i=!EOF;i++) to scan the whole file and fscanf(fp,"%s",result->country),etc in the loop to add the data to the structure of the element and finally insert that element to the queue list. However, when I try to do these operations, I only get to writing the name of the file and the program crashes.

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

struct List {
char country[20];
char code[5];
char capital[20];
struct List*next;

[Code] .....

View 1 Replies View Related

C++ :: Adding To The End Of A Doubly Linked Circular List?

Dec 2, 2014

Should my if statement be

if (tail== NULL) or if(tail->next == tail) ?

View 4 Replies View Related

C/C++ :: Adding File To The List Of Link Libraries

Jul 28, 2014

I tried to add a .a file to the list of link libraries, but when I build, I'm confronted with the following;

ld.exe||<the path>: Permission denied

I'm an admin on this machine - What?

View 14 Replies View Related

C/C++ :: Access Violation Adding A Pointer To List?

Feb 17, 2014

This code works:

//void Fighter::LoadAnimation(...){
std::list<SCML_SFML::Entity*> entities;
for(std::map<int, SCML::Data::Entity*>::iterator e = data.entities.begin(); e != data.entities.end(); e++) {
SCML_SFML::Entity* entity = new SCML_SFML::Entity(&data, e->first);
entity->setFileSystem(&fs);
entity->setScreen(&window);
entities.push_back(entity);//problem line
}
}

But if i change entities to a member variable, std::list<SCML_SFML::Entity*> Fighter::m_entities, it does not. Instead i get a write access violation when i try to push_back(entity). i need it to be a member variable because i need to use it in other member functions.

View 3 Replies View Related







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