C++ Linked List Operations -


i'm trying lab class , despite professor's lecture , accompanying reading, i'm having issues figuring out syntax. if can 1 of functions, feel can figure out rest.

this header

#pragma once  #include <string>  using namespace std;  struct listnode { public:     listnode( const string& thestring, listnode* pnext = null )     {         word = thestring;         pnextnode = pnext;     }      string word;     listnode* pnextnode; };  //add node (pnode) @ head of list.   //return pointer head node listnode* addfront( listnode* phead, listnode* pnode );  //add node (pnode) @ tail of list.   //return pointer head node listnode* addend( listnode* phead, listnode* pnode );  //remove (and cleanup after) node @ head of linkedlist (phead) //return pointer head node listnode* removefront( listnode* phead );  //remove (and cleanup after) node @ tail of linkedlist (phead) //return pointer head node listnode* removeend( listnode* phead );  //traverse linkedlist (phead) , delete nodes //return pointer head node listnode* removeallnodes( listnode* phead );  //traverse linkedlist (phead) , write out words in list //separated space void printnodereport( listnode* phead, ostream& out ); 

and cpp in need implement stubs

#include "linkedlist.h" #include <string> #include <sstream>  //add node (pnode) @ head of list.   //return pointer head node listnode* addfront( listnode* phead, listnode* pnode ) {     //stub      return phead; }  //add node (pnode) @ tail of list.   //return pointer head node listnode* addend( listnode* phead, listnode* pnode ) {     //stub     return phead; }   //remove (and cleanup after) node @ head of linkedlist (phead) //return pointer head node listnode* removefront( listnode* phead ) {     //stub     return phead; }  //remove (and cleanup after) node @ tail of linkedlist (phead) //return pointer head node listnode* removeend( listnode* phead ) {     //stub     return phead; }    //traverse linkedlist (phead) , delete nodes //return pointer head node listnode* removeallnodes( listnode* phead ) {     //stub     return phead; }   //traverse linkedlist (phead) , write out words in list //separated space void printnodereport( listnode* phead, ostream& out ) {     out << "here's list: ";     listnode* pcurr = phead;     while( pcurr != null )     {         out << pcurr->word << " ";         pcurr = pcurr->pnextnode;     }     out << "eol \n"; } 

first one:

listnode* addfront( listnode* phead, listnode* pnode ) {     pnode->pnextnode = phead;     return pnode; } 

one more defensive:

listnode* addfront( listnode* phead, listnode* pnode ) {     if(pnode == null)     {         //exception handling.     }     pnode->pnextnode = phead;     return pnode; } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -