### Help me write funcion deletenumber

I Tried but still not done !

hope you help me...Thanks you very much

Ex: 00042312 ->> delete the first zero 42312
0023014 ->> 23014

My code here

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137`` ``````#include "stdafx.h" #include #include using namespace std; class Node { public: int data; Node* next; }; class List { private: int count; Node* pHead; public: List() ; void addFirst(int) ; void addLast(int); void display(); int empty(); void removeFirst(); void clear(); int size(); List* deletethefirstzero(List*L); //HELP ME WRITE CODE HERE . THANKS YOU VERY MUCH ~List(); }; List::List() { pHead = NULL; count = 0; } void List::addFirst(int newdata) { Node* pTemp = new Node; pTemp->data = newdata; pTemp->next = pHead; pHead = pTemp; count++; } void List::addLast(int newdata){ Node *pTail = pHead; if(pHead == NULL){ addFirst(newdata); } else{ while(pTail->next != NULL){ pTail = pTail->next; } Node *pTemp = new Node(); pTemp->data = newdata; pTemp->next = NULL; pTail->next = pTemp; // pTail = pTemp; count ++; } } void List::clear() { while (! empty()) removeFirst(); return; } List::~List() { Node* pTemp = pHead; while (pTemp!=NULL) { pTemp = pTemp->next; delete pHead; pHead = pTemp; } } void List::display() { Node* pTemp = pHead; while (pTemp!=NULL) { cout << pTemp->data<<", "; pTemp = pTemp->next; } cout<next; delete pTemp; count --; } return; } int List::size() { return count; } List* deletethefirstzero(List*L){ //HELP ME WRITE CODE HERE . THANKS YOU VERY MUCH } int main() { List *aList = new List(); aList->addFirst(1); aList->addFirst(2); aList->addFirst(0); aList->addFirst(4); aList->addFirst(0); aList->addFirst(0); aList->addFirst(0); aList->display(); return 0; } ``````
At first you declare function `deletethefirstzero` as a member of List but you implement it as a global function.
Here's the code:
 ``123456789101112131415161718192021`` ``````class List { // ... void deletethefirstzero(); // ... }; // ... void List::deletethefirstzero(){ if(pHead!=NULL) { while(pHead->data==0) { removeFirst(); } } }``````
Last edited on
Topic archived. No new replies allowed.