Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-16-2004, 07:48 PM   #1
Registered: Aug 2003
Location: San Francisco, California
Distribution: Slackware
Posts: 158

Rep: Reputation: 30
Simple link list problem

can anyone look over this really quick and tell me some mistakes i made
#include <iostream>
using namespace std;
class windowLnkList{
	windowLnkList(windowLnkList *whereToPush = 0){
		///////Note: that above means the class after(Pnext)
		//////	     and below means the class before(Pprev)
		//This is where a chain link is inserted

		//(1)This is where we add references to the above/below class to this one
		Pprev = (whereToPush != 0) ? (whereToPush)               : (0);//Link to "object below's" location, if exists
		Pnext = (whereToPush != 0) ? (whereToPush->Pnext)        : (0);//Link to "object above's" location, if exists

		//(2)This is where we add references to this class to the above/below classes
		        (Pnext != 0)       ? (Pnext->Pprev = this)       : (0);//link object above, if app, to this location
			(whereToPush != 0) ? (whereToPush->Pnext = this) : (0);//link object below, if app, to this location
		if(Pprev != 0)//if this isn't the first item in the list
			Pprev->Pnext = Pnext;
		if(Pnext != 0)//if this isn't the last item in the list
			Pnext->Pprev = Pprev;
	void display(){
		cout << "Pnext: " << &Pnext << endl;
		cout << "this: " << this << endl;
		cout << "Pprev: " << &Pprev << endl << endl;
		if(Pnext != 0){
	windowLnkList *Pprev;
	windowLnkList *Pnext;
int main(int argc, char *argv){
windowLnkList class1;
windowLnkList class2(class1);
windowLnkList class3(class1);
Old 01-16-2004, 08:21 PM   #2
LQ Newbie
Registered: Sep 2003
Posts: 25

Rep: Reputation: 15
I am in the win,so can't compile it,
but in the main function, there must be a return type,
the other I an't help you!
Old 01-17-2004, 09:33 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
Re: Simple link list problem

Isn't this:
Pprev = (whereToPush != 0) ? (whereToPush) : (0);
Pnext = (whereToPush != 0) ? (whereToPush->Pnext) : (0);
..the same as:
Pprev = whereToPush;
Pnext = whereToPush->Pnext;

And isn't this:
(Pnext != 0) ? (Pnext->Pprev = this) : (0);
... a confusing way of saying:
if (Pnext != NULL) {
        Pnext->Pprev = this;
Old 01-22-2004, 12:41 PM   #4
Registered: Oct 2003
Distribution: Gentoo x86_64, Fedora Core 1 x86_32
Posts: 31

Rep: Reputation: 15
yeah, but I think the (0) should be changed to NULL to prevent any value from being stored there, and I personally like the ( ) ? : way of making if statements. Potato PotAto.

Old 01-22-2004, 02:05 PM   #5
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Ya, you definitly want to use NULL, there is a big different between something pointing to 0 and something pointing to NULL.

As far as the () ? :, it sucks for readability when statements get more complex then simple if-then-else statements which is why few people use it. In general most new guides to C and C++ tell people to shy away from them in general. I remember a professor I had a in college telling us if he saw those operators in our code we would be repeating his class.

It was his feeling that those, along with goto's, we completely unexceptable in 99.9% of all cases.

I complied and ran this code with a return statement and NULL's and it seams to work fine for me.

Last edited by jtshaw; 01-22-2004 at 02:12 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
link list reversl program vijeesh_ep Programming 3 02-27-2005 01:17 AM
need simple program to manage a mailing list linuxlimbo Linux - Software 0 12-21-2004 06:30 AM
What is Cursor implementation of Link List ? indian Programming 0 11-26-2004 11:54 AM
simple link question (ln) true_atlantis Linux - Newbie 1 12-02-2003 03:08 PM
Simple program link as Dockapp in Fluxbox Nerd2 Linux - Software 1 05-31-2003 09:29 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration