Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,014 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,473 people online right now. Registration is fast and FREE... Join Now!




Singly Linked, Circular List

 
Reply to this topicStart new topic

Singly Linked, Circular List, I'm having trouble with everything but the remove and insert part.

WSUbob09
1 Dec, 2006 - 07:08 PM
Post #1

New D.I.C Head
*

Joined: 1 Dec, 2006
Posts: 2


My Contributions
#include <iostream>
#include <iomanip>
#include <cassert>

using namespace std;

class node
{
private:
node( int = 0, node* = NULL );
int data;
node* next;
friend class list;
};

node::node( int x, node* p )
{
data = x;
next = p;
}

class clist
{
public:
clist();
~clist();
clist( clist& );
void Insert( int );
int remove( );
void print();
private:
node* tail; // points to the last node in the list
};

clist::clist()
{
tail = NULL;
}

clist::~clist()
{
node *ptr;
clist temp = head;
ptr = head;

while( ptr != NULL )
{
ptr = ptr->next;
delete temp;
temp = ptr;
}
}

clist::clist( clist& cl )/*CHANGE THIS*/
{
node* head;
node* newList = NULL;
node* tail = NULL;
while ( cl != NULL )
{
if ( newList == NULL )
{
newList = malloc( sizeof( cl.node ) );
newList->data = cl->data;
newList->next = NULL;
tail = newList;
}
else
{
tail->next = malloc( sizeof( cl.node ) );
tail = tail->next;
tail->data = cl->data;
tail->next = NULL;
}
cl = cl->next;
}
return( newList );
}

void clist::Insert( int x )
{
node *ptr; //pointer stored to use the value of head
ptr = tail->next; //puts the node that tail is pointing to, to the new int pointer
tail->next = new node (x,ptr); //makes tail point to the new node you add
// ******************************************DONE**********************************
********//
}

int clist::remove()
{
head = tail->next;
int x = tail->next->data;
tail->next = head->next;
// ******************************************DONE**********************************
********//
}

void clist::print( )/*CHANGE THIS*/
{
ptr = head;
if ( ptr != 0 )
{
while ( ptr->next != 0 )
{
cout<< ptr->x;
ptr = ptr->next;
}
cout<< ptr->x;
}
}


void main()/*CHANGE THIS*/
{
node *head;
node *ptr;

head = new node;
head->next = 0;
head->x = 12;
ptr = head;
if ( ptr != 0 )
{
while ( ptr->next != 0 )
ptr = ptr->next;
}
ptr->next = new node;
ptr = ptr->next;
ptr->next = 0;
}
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Singly Linked, Circular List
1 Dec, 2006 - 08:03 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,355



Thanked: 51 times
Dream Kudos: 25
My Contributions
Did you have a question? What portion is giving you difficulty? Can you post any error messages you are receiving, or provide a description of undesired begaviour?
User is online!Profile CardPM
+Quote Post

WSUbob09
RE: Singly Linked, Circular List
1 Dec, 2006 - 08:20 PM
Post #3

New D.I.C Head
*

Joined: 1 Dec, 2006
Posts: 2


My Contributions
QUOTE(Amadeus @ 1 Dec, 2006 - 09:03 PM) *

Did you have a question? What portion is giving you difficulty? Can you post any error messages you are receiving, or provide a description of undesired begaviour?



Yeah I have a pdf file of what we are supposed to do for the class I just have absolutely no idea how to do the program and if I dont get this done my proffessor is going to fail me and I need some help fast, its gotta be done by monday. I can e-mail you what i have if you want.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 09:00PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month