C++ :: Stack Based Linked List

Oct 23, 2014

I am trying to program a stack based linked list. Something very weird is happening with my program. Whenever i want to print with cout<< in specific places, it actually changes the data of the stack. Also, using endl after the cout also changes the data of the program.

#include <iostream>
using namespace std;
class node {
public:
int number;
node* nextPtr=NULL;

[Code] ....

View 7 Replies


ADVERTISEMENT

C++ :: Mid Of Stack Using Linked List

Apr 1, 2013

I am unable to make any logical algorithm to access middle of stack. I am using stack implemented with linkedlists, I have following functions available for stack like push,pop,top.

View 6 Replies View Related

C/C++ :: Implementing Stack Using A Double Linked List

May 12, 2014

So im trying to write a code that will take data in from a user and when that user enters specific character then i want to pop the top of the stack and place that node on a new stack. Then if the user enters a different specific character then i want to place what was just popped off the stack back on to the original stack. Anyways i'm just testing what i have without all the complicated stuff with the specific characters, but i get an error and i'm not not well versed in exception handling. So this is what i have so far. the push seems to work well but the pop seems to be giving me problems.

Stack::Stack(){
top = NULL;
bottom = NULL;
}
//method to push a line of text onto the stack
void Stack::push(string data)

[Code] .....

View 4 Replies View Related

C++ :: Overload Operator With Stack That Implements Linked List

Nov 10, 2013

struct Node {
int entry;
Node *next;
Node(); //1
Node(int item, Node *link = NULL); //2

[Code] .....

Implement: 1 2 3 4 5
and overload operator <<, >>, =

View 1 Replies View Related

C++ :: Array Versus Linked List Implementation For Stack

Nov 27, 2014

Basically what are the advantages and disadvantages of having an array implementation vs linked list implementation for a stack?

View 1 Replies View Related

C/C++ :: Linked List Implementation Of Stack For ReverseRows In Matrix

Nov 29, 2014

I had the following question in my exam paper and only got 2.5 out of a possible 7 marks.

Given the Matrix class:

class Matrix {
public:
Matrix(unsigned r, unsigned c);
Matrix(const Matrix<T>& rhs);
~Matrix();
const Matrix<T>&operator=(const Matrix<T>& rhs);

[code]....

Use the linkedStackType class (Linked list implementation of stack) and write a function reverseRows to reverse the order of rows in the matrix. Note that reverseRows is not a member function of the Matrix class therefore only the public interface of matrix can be used.

template<class Type>
struct nodeType {
Type info;
nodeType<Type> *link;

[code]....

View 2 Replies View Related

C++ :: 2D Array To Simulate Linked List For Stack Construction

Feb 13, 2013

I'm trying to implement 2d array to simulate linked list for stack and I faced several difficulties doing so.

How do I implement from Top to Bottom ordering? How do I check random index value for validity?

Source-code:

Code:
#include <iostream>
using namespace std;
int myTop, index, nex = -1;
int twoDimentionalArray[25][3], L[25];

[Code].....

And one more thing: how do I get straight 0 from 25 index in the first coulumn?

View 1 Replies View Related

C :: How To Insert A Node Into Linked List At Particular Location Based On Time

Feb 20, 2014

I'm trying to figure out how to insert a node into a linked list at a particular location based on a time..I have this declared outside of everything globally.

Code:

struct aTime {
char name[LENGTH];
int time;
struct aTime* next;
};

struct aTime* head = NULL; And then this function that is used to add nodes (aTime structs) to a linked list. It adds the first node fine, but not subsequent ones. I think this is because I have while p-> != NULL but it is always going to be null when the function is called since I create a new aTime struct. So I guess my question is how, after one struct has been added at the beginning, do I point to the head node and traverse the list, insert a node, and make sure everything is still linked? Do I need another temp aTime struct?

Code:

void add_time(char name[LENGTH], int seconds)
{
struct aTime *p;
p = (struct aTime *) malloc(sizeof(struct aTime));
if (head == NULL)
{
strcpy(p->name, name);
p->seconds = seconds;
}

[code]....

View 3 Replies View Related

C/C++ :: How To Access Linked List Functions From Stack Class Without Functions

Mar 20, 2014

I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.

We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.

As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.

NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.

Stack.h

#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;

[Code]...

View 3 Replies View Related

C++ :: Stack Implementation Of Linked Lists

Jun 7, 2014

I have this code that I need to memorize for my final. Memorizing code is easy for me, but I'm trying pretty hard to fundamentally understand the functions, and what they are doing (even using pen and paper, to draw and trace).For example, in the push function below, I understand everything, except why I'm setting ptr = p. I feel like p should be equal to NULL, then the next node I push should be equal to p, etc.

Stack & Stack::push(double x)
{
Node * p = NULL;
try
{
p = new Node;
}

[code].....

Also, are LL Queues that hard to implement once you can do them w/stacks - That will probably be something I have to code for my final, as well. Below is the full code for my Stack class.

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
class Stack
}

[code]....

View 1 Replies View Related

C# :: How To Stack List Items

Nov 18, 2014

I do some research about getting the coordinates from the list items but without success. I would like to make that when i press down my mouse button that little blocks fall "out" my mouse and stack on top of eachother.

that first works. When i press the mouse button i draw squares and the fall to the bottom of the screen, but the stack part not.

here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;

[Code]....

View 14 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++ :: Array Based Implementation Of Linked Lists

Jul 19, 2014

I first want to say that i am trying to solve my code without Pointers.

My goal is to..
1. Construct an empty 2D array with a capacity of 25. (list[25][2];)
2. Empty(): test if the stack is empty
3. Push(): add a value to the stack in the (list[i][0] = value;) position and (list[i][1] = previous list[i][0] position)
4. Top(); read the value(list[i][0]) at the top(count) of the stack
5. Pop(); remove the value at the top of the stack (list[i]= 0;)
6. Display(); displays all the elements in the stack going from the top to bottom order. (shows array index, data value, and next array index)

I have hit a road block and don't know what to fix or where to go from here.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
char name[5];
srand(time(0));
//Protoypes
void construction(int table[25][2]);

[Code]...

View 1 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 :: 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 Use List Box Based On Radio Button Selection

Jun 2, 2014

How to put together this assignment. Here is the assignment:

The ABC Shipping Company charges the Rates listed in the following table:

Weight of the package (in kilograms) Shipping rate per mile in California Shipping rate per mile other states

2 kg or less $2.0 $2.5

Over2 kg but not more than 6 kg $3.0 $3.5

Over 6 Kg but not more than 10 kg $3.5 $4.0

Over 10 Kg but not more than 30 Kg $4.0 $4.5

Over 30 kg $5.0 $5.5

Create an application that contains two radio buttons to select California or other states, a listbox for the user to select the package’s weight class, a textbox to enter the distance it is to be shipped, and a button to calculate and display the charges on a label control when it is clicked.

Input validation: Do not accept distances of less than 5 miles or more than 3000 miles

This is what I have so far. I don't know how to set up the listbox option for non california or how to set up a formula.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

[Code] ....

View 3 Replies View Related

C :: Sorting List Of Students Based On Their Test Scores

Jan 18, 2014

I need to sort these students based on their test scores.

My biggest problem is with my sort function. I am not sure of the syntax to call the items the proper way. I also don't know how to call the function properly as I know that i can't pass a int to a struct. Also not sure about the z malloc. Just threw that one in there.

Code:
struct student{
int id;
int score;
};
void sort(struct student* students, int n){
/*Sort the n students based on their score*/

[Code] ....

View 5 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 :: Doubly Linked List

May 15, 2013

I need to make the functions using these function prototypes. I am mainly having problems with GetFirst() and SwapData() but how to do it..

Header File with Prototypes
Code:
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
/**
* @file
* This file provided a doubly-linked list implementation capable of storing any arbitrary data.
* The list implementation relies on a chain metaphor: a list is merely a sequence of links
* (ListItems) and there is no separate construct to represent the entire list, each ListItem in it

[Code]....

View 14 Replies View Related

C :: Linked List Search

May 7, 2013

I read an article on linked list here: C Linked List Data Structure Explained with an Example C Program

Code:

struct test_struct* search_in_list(int val, struct test_struct **prev)
{
struct test_struct *ptr = head;
struct test_struct *tmp = NULL;
bool found = false;
}

[code].....

What is "if(prev)"? Wouldn't "prev" always have the same value? Secondly, if tmp is NULL (which will be the case when the loop if(ptr->val == val) finds a match the first time it is run), is *prev assigned a NULL?

View 1 Replies View Related

C :: Double Linked List

Jan 2, 2014

I'm having a small issue here with my linked list.I built a linked list with strings and it worked perfectly.Now since i'm using strtok() to separate the string.for now here's what i've got:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct dict_word *word;
typedef struct node *Node;
typedef struct double_linked_list *DLL;
}

[code]....

View 1 Replies View Related

C :: Static Linked List

Jan 6, 2014

I have the codes for the functions: "Given the functions that we have discussed and defined in the class and the code that we have created, create the code for the Delete Node function and the Search function. Create an application that will incorporate all the functions that we have discussed and the new ones that you need to create. The application should allow the linked list to be built initially from a text file. The application should then allow for the user select an operation to perform. The acceptable operations are

- to search for an item
- to delete an item
- to enter a new item
- to exit the application

After the initial build and loading of data from the textfile, the application should print a listing of each item in the list and the node that it is located in. after a delete or insert, the application should display an output of the list again showing each item in the list and the node that it resides in.

The data item for this problem will be the inventory structure that we created in class and the data is in the inventory file that you already have downloaded."

View 4 Replies View Related

C :: Singly Linked List

Mar 7, 2013

I am having difficulty getting my program to run. I have looked and looked many times trying to figure out what I am doing wrong. I have a hunch that it's my load function that's acting up, but from my perspective, my creation of my singly linked list looks good. From the creation of my singly linked list, does anything stand out as being abnormal?

Code:

typedef struct Node {
char word[LENGTH+1];
struct Node *Next;
} Node;
}

[code]....

View 6 Replies View Related

C :: Sorted Linked List

Apr 2, 2013

I been ask to create a sorted linked list module, and to test each function with 1 unit, 2 +.so i wrote my addtofront function( we have to use the same as the teacher)

Code:

struct MyList{
char * name;
Sorted * AddmyChar;
struct MyList * next;
}

[code]....

but i cant seem to test it because it always display a seg fault.... i dont know what i did wrong....how do i call this function in main to display a string i want?

View 9 Replies View Related

C++ :: Linked List Using Templates

May 27, 2014

I decided to make a linked list program using classes and templates.I implemented my linked list and added some basic functions, everything worked just fine. Then I proceeded to add templates...First, the error list:

#pragma once
template<class T>
class Node {
private:
Node* next;

[code]....

To sum up: Something's wrong with the templates that I used in "List.cpp" and what it could be.

View 5 Replies View Related

C++ :: Linked List Won't Take Big Numbers

Jan 2, 2013

My program is almost done all that is left is entering big numbers, the program can add and subtract small numbers but not big numbers because it puts them all in one node, I need the program to store each number in a node.

#include<iostream>
#include<string>
using namespace std;
class Node {
public:
int value;
Node * next;

[Code] .....

View 11 Replies View Related







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