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


ADVERTISEMENT

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++ :: Array Implementation Of Stack To Reverse Columns In Matrix

Dec 1, 2014

I had the following question in my exam paper and only got 1.5 out of a possible 6 marks. This is the question:

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 (Array implementation of stack) and write a function reverseCols to reverse the order of columns in the matrix. Note that reverseCols is not a member function of the Matrix class therefore only the public interface of matrix can be used.

//Implementation of Stacks as Array
template<class Type>
class stackType: public stackADT<Type> {
public:
const stackType<Type>& operator=(const stackType<Type>&);

[Code] ....

What is the correct solution must be to reverse the columns of the matrix?

View 1 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 :: Queue Implementation - Linked List

Mar 23, 2013

I am trying to create a code to represent a queue using a linked list but i get the disturbing "Segmentation fault coredumped" after compilation.

Code:

#ifndef QUEUE_H
#define QUEUE_H
#include <stdbool.h>

typedef int Item;
typedef struct queue_type *Queue;
typedef struct node *return_node;

[Code] .....

View 2 Replies View Related

C++ :: Linked List - Implementation At Nth Node

Feb 27, 2015

I have to write a program which has the user be able to enter a specific value at a specific position of the linkedlist, replacing that node with the user defined value

EX: Enter the value 5 at 2nd node, which will override the old value at the 2nd node with the new one

I am getting a compiler error which terminates my program right after the user presses the return key after he/she has given a position to change the value

Error: Unhandled exception at 0x013C50C1 in Linked(1).exe: 0xC0000005: Access violation reading location 0x0000812B.

I am not going to show the whole code as the problem resides solely on the insert function:

void TheNode::insert(double num, int choice) {
int post = 0;
MyNode *ptr = new MyNode;
(*ptr).value = num;
MyNode *previous = head;
MyNode *current = head->next;

[Code] .....

View 1 Replies View Related

C++ :: Double Linked List Implementation

Dec 27, 2013

I'm trying to set up a simple implementation of a double linked list... But I seem to some mistakes.

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define ValueType int
struct vertex {

[Code] ....

I get 'Test: root exists' printed out, but not the loop through my linked list.

View 11 Replies View Related

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++ :: Linked List Class Node Implementation

Mar 26, 2014

I am studying this sample code for linked list class node implementation. I am not 100% sure how this code keeps track of the head node. Here's what I know so far, and if you want to add/correct anything feel free to do so:

class Node {
public:
Node(); // constructor of class node without arguments
Node(int, Node*); //constructor with arguments of int type and a pointer node type
Node* next() const;
void setNext(Node*); //member fun, returning a pointer of node type
void setKey(int);

[Code] ......

View 8 Replies View Related

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 View Related

C++ :: Linked List Interface / Implementation And Driver File

Jun 12, 2013

I am having difficulty calling the constructor in interface portion of my program. I get the error: no matching function for call to ‘Node::Node(int, NULL)’ when I try to call it on line 26 within the main function.

code:
interface: [URL]
implementation: [URL]
main file: [URL]

View 7 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++ :: 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 :: Linked List Or Hash Table For Matrix Operations And Representation

Jul 21, 2014

I have matrix in C with size m x n. Size n isn't known. I want to have operations on matrix such as : delete first element and find i-th element. (where size m woudn't be too big , from 10 to 50 columns).

What is more efficient to use, linked list or hash table? How can I map each column of matrix to different element of linked list or hash table; depends what I choose to use?

View 5 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 Using Arrays

May 31, 2014

Code:

#include <stdio.h>#include <unistd.h>
#include <stdlib.h>
#define STACKSIZE 100
struct stackk
{
int top;
int items[STACKSIZE];
};
typedef struct stackk *s;

[Code]...

View 1 Replies View Related

C++ :: Stack Implementation With Struct

Apr 7, 2014

I am trying to implement a stack class which has struct data type as its private member. I am getiing the following error ,

bash-3.2$ g++ stack_str_arr.cpp
stack_str_arr.cpp: In member function ‘void stack::push(int)’:
stack_str_arr.cpp:39: error: ‘top’ was not declared in this scope
stack_str_arr.cpp: At global scope:
stack_str_arr.cpp:43: error: no ‘void stack::display()’ member function declared in class ‘stack’

Code:

#include<iostream>
using namespace std;
#define MAX 5
class stack {
public :
stack();

[Code] ....

View 2 Replies View Related

C :: Program To Evaluate Postfix Expression Using Array Implementation Of Stack

Apr 26, 2014

Write a program that evaluates postfix expression using array implementation of stack.

The expression [the input] is evaluated from left to right using a stack. When the element read from the expression is an operand, push it into the stack.When the element read from the expression is an operator: Pop two operands from the stack.Evaluate the two operandsPush the result of the evaluation into the stack.

The final result lies on the top of the stack at the end of the calculation. Make sure to display the result before terminating the program.Write a program that evaluates postfix expression using array implementation of stack.

Code:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M 20

typedef struct{

[Code] ....

View 1 Replies View Related

C++ :: 4x4 Matrix Inverse Implementation

Sep 19, 2013

I'm implementing a 4x4 matrix class and all is going well until the inverse function turned up. I'm trying to implement the inverse function, but I can't seem to get my head around it.

I've tried the internet, but found nothing useful. Also, I've looked into source code of other programs/libraries that implement a matrix class, but the code is unreadable.

How I can implement this damn 4x4 inverse function? I know the process of inversion, but putting that process into code is proving quite a challenge.

In addition, I do have some code, but it's unmanageable and inefficient at the moment. If you want to see it, just ask.

Additional question(s): What applications does the inverse matrix have in 3-D?

View 3 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# :: 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 :: 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++ :: 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







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