Stack strings ADT, using a doubly linked list

trying to implement a Stack of strings ADT, using a doubly linked list

Page 1 of 1

1 Replies - 7263 Views - Last Post: 24 January 2010 - 03:24 AM Rate Topic: -----

#1 forurup  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-January 10

Stack strings ADT, using a doubly linked list

Posted 24 January 2010 - 03:20 AM

hi
i am not new to c++ programing but i used 4 years back . So i lost touch with it.i am trying to implement a Stack of strings ADT, using a doubly linked list and As a minimum my class should offer Default constructor, copy constructor,Destructor,Overloaded assignment operator.i written some code like this

list.h

#ifndef STACK_H
#define STACK_H
#include "iostream"
using namespace std;

struct node{
			string name;
			string course;
			node* next;
			node* prev;
			
			};

class list{
public:
		static node* newnode();
		//static void node* searchnode();
		static note* deletenode();
		static node* display();
private:
		static node* firstnode;
		static node* lastnode;
};

#endif




and

list.cpp


#include "iostream"
#include "stack.h"
using namespace std;

node* list::newnode()
{
node* nodehold;
nodehold = new node;
cout << endl << "Enter the Name:";
cin >> nodehold->name;
cout << endl << "Enter the Cource:";
cin >> nodehold->course;

if(firstnode == NULL)
	{
		firstnode = nodehold;
		lastnode = nodehold;

		nodehold->next = NULL;
		nodehold->prev = NULL;
		
		return nodehold;
	}
if(firstnode != NULL)
	{
		nodehold->next = lastnode;
		nodehold->prev = NULL;
		return nodehold;
	}
}
node* list::deletenode()
{
node *nodehold;
nodehold = firstnode;
firstnode = firstnode->next;
delete nodehold;
return;
}
//node* list::searchnode()
//{
//
//}
node* list::display()
{
	node* nodehold;
	if(firstnode == NULL)
	{
		cout << endl << "There are no nodes in list";
		return;
	}
	else
	{
		nodehold = firstnode;
		while(nodehold != NULL)
		{
			cout << endl <<"Name:"<< nodehold->name << "\tCourse:" << nodehold->course;
			nodehold=nodehold->next;
		}
		cout << endl << "End of list";
	}
}




and

listmain.cpp


#include "iostream"
#include "stack.h"
using namespace std;

void main()
{
	int option;
	//node list::firstnode=NULL;
	//node list::lastnode=NULL;
	firstnode=NULL;
	lastnode=NULL;
	do
	{
	cout << "Please select an option :" << endl;
	cout << "0. Exit the program." <<endl;
	cout << "1. Add a node" << endl;
	cout << "2. Delete node from the list." << endl;
	//cout << "3. search node from the list." << endl;
	cout << "4. display node from the list." << endl;
	cout << endl << " >> ";

	switch (option)
		{
			case 1 : node* list::newnode();
					break;
			case 2 : node* list::deletenode(); 
					break;
			//case 3 : node* list::searchnode(); 
			//		break;
			case 4 : node* list::display(); 
					break;
		  
		}
	}while(option != 0);
}




when i try to run i got 19 errors
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
warning C4183: 'deletenode': missing return type; assumed to be a member function returning 'int'
error C2065: 'firstnode' : undeclared identifier
error C2065: 'lastnode' : undeclared identifier
error C2761: 'node *list::newnode(void)' : member function redeclaration not allowed
error C2761: 'int *list::deletenode(void)' : member function redeclaration not allowed
error C2761: 'node *list::display(void)' : member function redeclaration not allowed list.cpp
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
warning C4183: 'deletenode': missing return type; assumed to be a member function returning 'int'
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

whats wrong with my code ...help me

Is This A Good Question/Topic? 0
  • +

Replies To: Stack strings ADT, using a doubly linked list

#2 Anarion  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,456
  • Joined: 16-May 09

Re: Stack strings ADT, using a doubly linked list

Posted 24 January 2010 - 03:24 AM

These errors are totally obvious, just read what they say to you, and go to correct them. (don't have the time to look them up myself right now)
Just one thing quickly I noticed, members of node struct have to be public so you can use them from outside it's scope:
struct node{
public:
	string name;
	string course;
	node* next;
	node* prev;	
};


Also... :crazy: "iostream" this is a Big mistake, it has to be <iostream>

This post has been edited by Anarion: 24 January 2010 - 03:27 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1