| | |
Stack using a linear linked list of arrays
![]() |
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
Hi everyone, I've worked on this thing for about three days now and am really getting frustrated. I need to make a stack using linear linked lists of arrays. I've got my class to compile without complaining, but am really struggling with the function definitons of push and peek. Any help would be greatly appreciated. Here is what I have so far:
C Syntax (Toggle Plain Text)
//function to "push", move data to the stack void Stack::push(char newItem[]) { //create new node node *newPtr = new node; assert(newPtr != NULL); newPtr->item = newItem; //inserts new node newPtr->next = topPtr; topPtr = newPtr; } //function to return the top item in stack void Stack::peek(char stackTop[]) const { stackTop[] = topPtr->item; }
Last edited by niek_e; 33 Days Ago at 8:39 am.
probably want something like this. The function should return a const char*
C Syntax (Toggle Plain Text)
const char* Stack:peek(void) const { return topPtr->item; } // example calling Stack stack; const char* item = stack.peek();
My NewYear's resolution is to lose weight.
Weight Lost since 1 Jan 2010: 8.7 lbs
Weight Lost since 1 Jan 2010: 8.7 lbs
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
I figured out how to use the peek function by changing a few things in my class, but I'm still lost on how to assign an array of characters to a node in a linked list. I keep getting the compiler error "incompatible types of assignment char to char[]" Here is the code I have... I'm not sure I've changed it at all, most of the changing has been within my class.
C Syntax (Toggle Plain Text)
void Stack::push(char newItem[]) { node *newPtr = new node; assert(newPtr != NULL); newPtr->item = newItem; //setting char item[] to newItem[] topPtr = newPtr; }
Last edited by ~s.o.s~; Nov 5th, 2006 at 12:48 pm.
![]() |
Similar Threads
- linked list implementation of stacks (C)
- linked stack question. (C)
- doubly linked list implementation (Java)
Other Threads in the C Forum
- Previous Thread: Help: Passing arrays between functions
- Next Thread: Help making an Output File look presentable
Views: 6888 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C
#include * .net api array arrays binarysearch c++ changingto char cheating cm command conversion copyimagefile creafecopyofanytypeoffileinc data database dev-c++ directory dynamic engrish error execv factorial file fork forloop framework function functions givemetehcode givemetehcodez grade graphics gtkwinlinux hacking haiku histogram homework include incrementoperators input iso kernel keyboard lazy line linked linkedlist linux list lists loop looping loopinsideloop. lowest malloc matrix microsoft mqqueue mysql no-effort output overwrite parallel pdf pointer pointers posix problem process program programming radix read recursion recv research reversing segmentationfault sequential socket sockets special spoonfeeding standard string strtok structures student system testing threads turbo-c turboc unix user whythiscodecausesegmentationfault windowsapi






