Please can some one help me here;

I have 4 questions to solve

/a. Write a member function to check whether two singly Linked List have
the same contents.

//b.Write a member function to reverse a singly Linked List using only
one pass through the list.

//c.Insert a new node into a singly linked List(i) Before and (ii) After a node
pointed by p in this list ( possibly the first or the last). Do not use a
loop in either operations.

//d. Attach a singly linked list to the end of another singly linked list.

I have done some coding shown below:

//
//************************ intSLLst.cpp **************************

``````#include <iostream>
#include <stdlib.h>
#include "IntSLList.h"

IntSLList::~IntSLList() {
for (IntSLLNode *p; !isEmpty(); ) {
}
}

if (tail == 0)
}

if (tail != 0) {      // if list not empty;
tail->next = new IntSLLNode(el);
tail = tail->next;
}
else head = tail = new IntSLLNode(el);
}

if (head == tail)     // if only one node on the list;
delete tmp;
return el;
}

int IntSLList::deleteFromTail() {
int el = tail->info;
if (head == tail) {   // if only one node on the list;
}
else {                // if more than one node in the list,
IntSLLNode *tmp; // find the predecessor of tail;
for (tmp = head; tmp->next != tail; tmp = tmp->next);
delete tail;
tail = tmp;      // the predecessor of tail becomes tail;
tail->next = 0;
}
return el;
}

void IntSLList::deleteNode(int el) {
if (head != 0)                     // if non-empty list;
if (head == tail && el == head->info) { // if only one
delete head;                       // node on the list;
}
else if (el == head->info) {  // if more than one node on the list
delete tmp;              // and old head is deleted;
}
else {                        // if more than one node in the list
IntSLLNode *pred, *tmp;
tmp != 0 && !(tmp->info == el);// is deleted;
pred = pred->next, tmp = tmp->next);
if (tmp != 0) {
pred->next = tmp->next;
if (tmp == tail)
tail = pred;
delete tmp;
}
}
}

bool IntSLList::isInList(int el) const {
IntSLLNode *tmp;
for (tmp = head; tmp != 0 && !(tmp->info == el); tmp = tmp->next);
return tmp != 0;
}
// a. Write a member function to check whether two singly linked lists have the same contents
bool IntSLList::operator==(const IntSLList& list2) const {
for ( ; lst1 != 0 && lst2 != 0 && lst1->info == lst2->info;
lst1 = lst1->next, lst2 = lst2->next);
return lst1 == lst2; // true if both are null;
}

//b.Write a member function to reverse a singly Linked List using only one pass through the list.

void IntSLList::reverseList(){

p1->next=0;
IntSLLNode *p2 = p->next;
}
while(p2!=0);
{
p2->next=p;
p->next=p1;
}
}

void ostream& operator<< (ostream& out, const IntSLList& list) {
for (IntSLLNode *p = list.head; p != 0; p = p->next);
out << p->info << ' ';
out << endl;
return out;
}``````

What is the problem? Also, please use code tags.

is your function reverseList working ?

is your function reverseList working ?

At the moment I am working on it.
If someone can solve parts C and D.
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.