I am working on creating a linked list to connect the previous value number (or string) to another value I asked this question before I am just guessing I did it completely wrong since no one responded. So what would be the best way to start the function. I need to linked the list of strings together and be able to add a new name and be able to add name either a the end or middle easily Example [John]->[Stewart]->[Hanna} Insert Patrica in second spot [John]->[Patrica]->[Stewart]->[Hanna] [CODE] //Platform: C++ Win32 Console Visual Studio 2010 #define _CRTDBG_MAP_ALLOC #include <iostream> #include <stdlib.h> …

Member Avatar
Member Avatar
+0 forum 5

please help me in my code the error appears and i can`t figure it out. i used to write a program that will accepts the user input, but only a word then the program will scramble the word that had been inputted by the user and display it on JFrame(WINDOW) [code]package gui; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane; public class FieldInputs extends JFrame { private JLabel wordL, scrambleWordL; private JTextField wordTF, scrambleWordTF; private JButton scrambleB, exitB; private ScrambleTheWordButtonHandler sbHandler; private ExitButtonHandler ebHandler; private static final int WIDTH = 400; private static final int HEIGHT = 400; public FieldInputs(){ …

Member Avatar
Member Avatar
+0 forum 9

Hey all, I've been programming an ISBN system of sorts and I'm a little stuck (again). I want to output my linked list to a text file, so I setup the code like this: [code] void saveList(char fileName[40]) { for ( list< Publication* >::iterator it = pubList.begin(); it != pubList.end(); it++) { try{ std::ofstream ouf(fileName); if( !ouf ) throw std::ios::failure( "File Error" ); ouf<<"Publication,"<<(*it)->getPublisher()<<","<<(*it)->getIsbn(); ouf.close(); }catch( const std::exception& e){ std::cerr <<e.what()<<endl; } } }[/code] Now saving like this works alright with a small issue. I can only access the public functions of the base class object, I can't access the …

Member Avatar
Member Avatar
+0 forum 8

Hey all, I'm attempting to use an STL List to store a list of objects. Now I realise it's quite trivial to store a list of objects of my own definition. My real question is, how do I fill the list with objects that inherit from a base class. E.g. I have a class called Book which has the derived class Publication. How would I get the list to accept the base class aswell as derived classes? currently I am doing it something like this: [CODE] list<Book> objectList; //define list Book temp("Title", "ISBN"); Publication pubTemp("Title", "ISBN", "Publisher"); objectList.push_back(temp); objectList.push_back(pubTemp); [/CODE] …

Member Avatar
Member Avatar
+0 forum 4

Hey all! I'm new to the forum and a little wet around the programming ears so to speak. Anyway I have a question regarding Linked Lists. I know that typically a linked list looks like this: [CODE] struct Node { dataType varName; //data type and variable name Node *next; //points to next node in list }; [/CODE] Now I know I can use standard datatypes such as char, int, string and so on so forth quite easily in a linked list, but what I want to do is use my own data type. In this case I have created a …

Member Avatar
Member Avatar
+0 forum 3

[code] class List(): def __init__(self,values=0): self.numb=values self.linker=self def add(self,values): self=self.linker self.numb=values self.linker=List() def show(self): while self!=self.linker: print self.numb self=self.linker [/code] In main call i want some thing like this [code] list1=List() list1.add(43) #i want to add numbers to liked list node like this list1.add(22) list1.add(938) list1.show()#Then retrieve it from the linked list(list1) [/code] I am not sure about the logic because when i want to add third number it just saves it to the 2nd node of the linked list ,so more precisly its storing first list.add(43) and list.add(938) where is list1.add(22) gone ? ...Please write some code and explain …

Member Avatar
Member Avatar
+0 forum 2

I just cant get my head around it. Is there another way going through a singly linked list without using some kind of helper function? The header file wants me to implement: [CODE]size_t priority_queue::size() { /* code here */ }[/CODE] Now I just could create a helper function that has a node as parameter and as long as node->get_next() != 0 I recursively call the helper and add 1 to a counter. But is there actually a way to get through a singly linked list without a helper function? I hope I was clear enough.

Member Avatar
Member Avatar
+0 forum 4

Hello. I'm currently making a program that deals with a priorityQueue and inheritence/polymorphism. Student -> undergrad -> coop_student or student -> grad Now, the queue takes in the data and just puts it in a linked list and gives it a priority. That way, there are 3 queues and we dequeue from the first going to last. Here are the snippets that have the problem. Note: I was told that I don't need an operator=, but if I do, I can add one. priorityQueue.cpp:30: error: no match for ‘operator=’ in ‘n->node::data = theStudent’ [CODE]void priorityQueue::enqueue( student * theStudent, int priority …

Member Avatar
Member Avatar
+0 forum 3

I just started looking at iterators in my C++ class and don't think I fully understand enough about them to actually create one. I need to add an iterator to this doubly linked list program: [CODE]#ifndef CSLIST_H #define CSLIST_H #include <iostream> #include <cstdlib> using namespace std; template <class T> struct node // Create a structured node object { T value; // value the node stores node<T>* next; // pointer to the next node node<T>* prev; // pointer to the previous node }; template <class T> class cslist { public: cslist(); // default constructor int size() const; // return the number …

Member Avatar
Member Avatar
+0 forum 2

Hey, i know you are all probably very bored with the infix to postfix program and its many incarnations but i seem to be having a problem getting the linked list we have to use as a stack to work. More specifically; pushing to the stack, reading from the top of the stack and deleting from the stack are all ok, the problem comes from trying to read the empty stack to check that its empty (should return a "#") somewhere the error checking is not working and i cant for the life of me find out where!! header file: …

Member Avatar
Member Avatar
+0 forum 1

Hello all, here is the code I came up with for implementing a circular linked list. I get a segmentation fault when I create the list with just one node. With size > 1 circular list works fine! Im not sure but I think it may have something to do with the head pointer pointing to itself.. any ideas? [CODE] #include <stdio.h> using namespace std; #ifndef CIRCULARLINKEDLIST_H_ #define CIRCULARLINKEDLIST_H_ class Node { public: char* value; Node* next; int index; Node(int in, char* val,Node* nextNode){ index = in; value = val; next = nextNode; } }; class CircularLinkedList { public: Node* …

Member Avatar
Member Avatar
+0 forum 9

Hi all, I wrote a program that has many functionalities but I can not swap 2 elements of 2 nodes in the linked list.Actually I can swap 2 nodes by changing their links but I can not swap 2 elements when the user requested 2 elements swapping.Here is my code without any swap operation.Again I have to say I want to do this swap operation by swapping 2 node elements not changing node links.How can I get rid of this problem?Any help will be appreciated. #include <stdio.h> #include <stdlib.h> struct node{ int data; struct node *next; }; typedef struct node …

Member Avatar
Member Avatar
+0 forum 3

Yes, I have looked in the forums for answers and have found plenty, and am asking about what I could not find. And yes, this is homework, but I need help and my professor has not responded thus far... now on to business. Description of Goal: Make a Set Data Structure using a singly Linked List. The goal is to read word by word from a text file, and (if it hasn't already been added to the list) add it to the linked list. Simple, right? My problem: I am not getting the correct outputs. I suspect that my pointers …

Member Avatar
Member Avatar
+0 forum 16

Hi, I wrote a program that inserts nodes into a linked list in descending order.But whenever I test my code with numbers 12,14,13,19,7 in this order.Whenever I entered 7 I took 7 is already in the list.But as easily seen 7 is not in the list before I inserted.After give this error,if I choose print option by typing 2 my program entered in an infinite loop.I can not see my mistake and I am very confused.Please help me.My code is in the following: [CODE]include include struct node { int content; struct node *nextLink; }; typedef struct node NODE; void print(NODE …

Member Avatar
Member Avatar
+0 forum 3

I have an assignment where I need to do some operations on polynomials (add, multiply, ...) which are represented by linked lists. Part of the assignment is to make an inner class Term containing two int fields and a constructor with coef and exp ints) I also need an inner class Node that has a term and node field, along with a constructor that also inludes term and node parameters. I also need to have a private Node field that will represent the polynomial as a singly linked list with a head (and ordered by exponent from smallest to largest). …

Member Avatar
Member Avatar
+0 forum 1

There are n persons numbered from 0 to n - 1 standing in a circle. The person number k, counting from the person number 0, is executed. After that the person number k of the remaining persons is executed, counting from the person after the last executed one. The process continues until only one person is left. This person is a survivor. The problem is, given n and k detect the survivor's number in the original circle. 'Quoted from [URL="http://acm.uva.es/archive/nuevoportal/data/problem.php?p=3521"]http://acm.uva.es/archive/nuevoportal/data/problem.php?p=3521[/URL] :)I've written the code below.It works properly unless the user enters '1' as the period of counting:$ [CODE] // Joseph …

Member Avatar
Member Avatar
+0 forum 2

Hello everyone...I'm trying to create a journey planner for an underground system...but the first thing Is to create the skeleton of the underground system... my problem is I don't know how to add more links to a single node when the station has an intersection with other lines... [CODE]public class LinkedList { public LinkedList( ) { header = new ListNode( null ); } public boolean isEmpty( ) { return header.next == null; } public void makeEmpty( ) { header.next = null; } public LinkedListIterator zeroth( ) { return new LinkedListIterator( header ); } public LinkedListIterator first( ) { return new …

Member Avatar
Member Avatar
+0 forum 6

Hi, I am working on some practice problems for my class and I keep getting stuck on this problem. It is using linked list, I am bit stuck. The problem is to write a function int testloop (listnode *head) that checks to see whether the list 'head' contains a loop. I just need help on how to approach the problem [CODE]#include <iostream> using namespace std; class listnode { public: listnode *next; }; listnode *l[4]; void create_list(); int testloop(listnode *head); int main() { int i; cout << "creating lists......\n"; create_list(); // creating lists in *l[4] for (i=0; i<4; i++) { cout …

Member Avatar
Member Avatar
+0 forum 3

Hi - i have been trying to create a linked list in C using structs and there are a couple of things i am stuck with how to declare the node front and back and do i keep repeating myself? Also in the function push back how can i use the linked list i created ? [CODE]#include <stdlib.h> typedef struct node { int data; struct node* next; struct node* prev; }; typedef struct llist { struct node* front; struct node* back; }llist; llist* linked_list_create() { llist* aLL = malloc(sizeof(llist)); aLL->front = 0; aLL->back = 0; return aLL; } int linked_list_push_back(llist* …

Member Avatar
Member Avatar
+0 forum 4

Hi, I created a program using the linkedlist package. I encountered an error when I tried to insert an element... By the way here's my code... [CODE] import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.util.*; class guiListOperations3 extends JFrame implements ActionListener { static LinkedList <String> list=new LinkedList <String>(); static JLabel lblElement,lblDisplay,lblPos; static JTextField txtInput1,txtDisplay1,txtDisplay2,txtPos; static JButton btnAdd,btnRemove,btnPeek,btnCancel,btnClear; static int pos=0; public guiListOperations3() { Container drum=getContentPane(); drum.setLayout(new FlowLayout()); lblElement=new JLabel("Enter Element: "); drum.add(lblElement); txtInput1=new JTextField(10); drum.add(txtInput1); lblDisplay=new JLabel("List: "); drum.add(lblDisplay); txtDisplay1=new JTextField(10); txtDisplay1.setEditable(false); drum.add(txtDisplay1); lblPos=new JLabel("Position:"); drum.add(lblPos); txtPos=new JTextField(1); drum.add(txtPos); btnAdd=new JButton("Insert"); drum.add(btnAdd); lblDisplay=new JLabel("To delete element:"); drum.add(lblDisplay); btnRemove=new JButton("Remove"); drum.add(btnRemove); …

Member Avatar
Member Avatar
+0 forum 1

i am trying to move the node in the first item from the list and add it to the back of the list 1->2->3 becames 2->3->1 instead i get 3 1 2 [CODE] #include <iostream> using namespace std; struct nodeType { int info; nodeType *link; }; void createList(nodeType*& first, nodeType*& last); void printList(nodeType*& first); void moveFront2Back(nodeType*& first, nodeType*& last); int main() { nodeType *first, *last; int num; createList(first, last); printList(first); moveFront2Back(first,last); system("PAUSE"); return 0; } void createList(nodeType*& first, nodeType*& last) { int number; nodeType *newNode; first = NULL; last = NULL; cout<<"Enter an integer (-999 to stop): "; cin>>number; cout<<endl; …

Member Avatar
Member Avatar
+0 forum 4

Dear friends, hello to you all as this is my first thread - question to the forum. This is my problem, which is a school exersize: I create a linked list which contains three numbers r,c,d per node From this list I have to create a hash table htable[7] with hash function hk=d mod 7 my idea of doing it is through the following code, where htable and fnl are hash tables and curr is a structure of the same type. [CODE] while (curr != NULL) { if (htable[hk]==NULL) { htable[hk]=curr; fnl[hk]=curr; } else { fnl[hk]->next=curr; fnl[hk]=curr; } curr=curr->next;[/CODE] doing …

Member Avatar
Member Avatar
+0 forum 2

Hello everyone. I've been trying to implement a linked list in C++. I found this implementation on the web, where they created a struct for the list's nodes. When trying to add a new node to the list, I get this error: [B]List.C: In member function `bool Linked::addNode(Point)': List.C:23: error: no matching function for call to `Linked::node::node()' List.H:35: note: candidates are: Linked::node::node(const Linked::node&)[/B] And here's my Code, and thank you very much.. :) [B]List.H[/B] [CODE]#ifndef _AUXILIARY_H_ #define _AUXILIARY_H_ #include <string.h> #include <math.h> class Linked { public: // Constructor: initializes a set of nodes Linked(); // Linked methods bool addNode(Point p); …

Member Avatar
Member Avatar
+0 forum 5

THis is what I need to do...I need help with the third point [INDENT]1. Write a class OrderedList. The implementation of OrderedList must be as a linked list of Comparable elements. The list items are maintained in ascending order at all times. On this assignment, no indexing methods are allowed. The following methods are required: int size() //Return the number of items in the list boolean contains(Comparable item)//Return true iff item is stored in the OrderedList void insert(Comparable item)//Add an item to the OrderedList Comparable remove(Comparable item) //Remove and return a matching item Also, provide a default constructor and a …

Member Avatar
Member Avatar
+0 forum 8

Hello everybody! I have to Questions to ask please: 1) How can I find the maximum value in a single linked-list recursively? this is what I tried to do: int findMax(int key){ Node max=head; while (max != null){ if (max < max.getKey()) return(max.getNext()); } } it ends up to an error.. :( 2) How can check palindrome in a single linked-list recursively? Thank you for All ^ ^

Member Avatar
Member Avatar
+0 forum 18

[CODE]/*Task: Two ordered linklist contain number. eg.1->2->3-> and 2->3->5 **Print** union of them eg.1->2->3->5 ,remove duplication, can't change linklist Problem : 1. append() might need to be modified. 2. dnot't know how to use append() to complete the task. */ #include <stdio.h> #include <malloc.h> #include <string.h> #include <stdlib.h> typedef struct lnode Lnode; struct lnode { int data; Lnode *next; }; Lnode * makeNode( int data ) { Lnode *new_node =(Lnode *)malloc( sizeof( Lnode )); if( new_node == NULL ) { fprintf(stderr,"Error: memory allocation failed.\n"); exit( 1 ); } new_node->data = data; new_node->next = NULL; return( new_node ); } Lnode * …

Member Avatar
Member Avatar
+0 forum 1

Hello all, I have a question: What are the advantages & disadvantages of the circular linked list compared with: a. Usual linked list b. Doubled linked list Although the implementation of the usual list functions & the circular list functions are similar…when do we have to use it?? or in which situations the circular list is better than the usual list? :rolleyes: Thank you, ;)

Member Avatar
Member Avatar
+0 forum 5

Hi guys. For some reason I cannot get the linked list to print. I want to copy it(which works) but I cannot get the list to print after copying it. Any suggestions? [CODE]#include <iostream> using namespace std; struct node { int info; node* next; }; int main() { node* list; list = new node; list->next = NULL; node* curr = list; list->info = 0; int num = 1; while(num <= 100) { node* temp = new node; if (temp == NULL) { cout << "Error. No memory was allocated."; break; } temp->info = num; curr->next = temp; curr = curr->next; …

Member Avatar
Member Avatar
+0 forum 4

this is a program that my teacher gave me in the class. but i didn't understand it....please explain it to me step by step... [code= c++] #include<iostream.h> class queue { int element; queue* next; public: queue* enqueue(queue*,int); queue* dequeue(queue*); void queue_display(queue*); }*head,*tail,object; queue* queue::enqueue(queue* head,int key) { queue* temp; temp=new queue; temp->element=key; temp->next=NULL; if(head==NULL) head=temp; else tail->next=temp; tail=temp; return head; } queue* queue::dequeue(queue* head) { queue* temp; if(head==NULL) { cout<<"\nit is impossible to dequeue an element as "; return NULL; } else if(head->next==NULL) { cout<<"\nthe element dequeued from the queue is: "<<head->element<<endl; return NULL; } else { cout<<"\nthe element dequeued …

Member Avatar
Member Avatar
+0 forum 1

Pretty interesting problem about linked list. This program is about autobuses. Each autobus is given by brand, registration number, number of seats, kilometres and year when the bus was made. The program is organised as menu and when you hit number it calls some function. Problematic function: it should NOT PASS autobuses with the same registration number but this function(int povtorenie()) doesn't work properly if you type equal registration numbers on positions different from 1 and 2. [CODE]int povtorenie(struct node* call) { char* a=new char[20]; strcpy(a,call->regnomer); call = call->next; while(call!=NULL) { if(strcmp(call->regnomer,a)==0) return 1; else return 0; call = call->next; …

Member Avatar
Member Avatar
+0 forum 2

The End.