954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

one way linear link lists

[php]
#include

using namespace std;

typedef struct Template
{
int a;
Template * link; // goes forward (one way reference)

} list;

typedef list * listptr;

int main()
{
listptr head; // head is a type listptr
listptr p ;
listptr next ;


head = NULL; //therfore make it null
next = NULL;

for(int i =0 ; i<4 ; ++i)
{
p = new list;// create new element of p type of listptr (new structure)

cin >> p->a;

cout << p->a <link = next;
cout << p <

Acidburn
Posting Pro
511 posts since Dec 2004
Reputation Points: 12
Solved Threads: 5
 

Which way are you trying to build the list? Are you trying to have the most-recently entered element be at the front of the list, or are you trying to have the most-recently entered element be at the end of the list. Right now, it looks like you want the former, but since you appear very confused, I have to ask.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 
Which way are you trying to build the list? Are you trying to have the most-recently entered element be at the front of the list, or are you trying to have the most-recently entered element be at the end of the list. Right now, it looks like you want the former, but since you appear very confused, I have to ask.

hey dude, thanks for taking the time to read / reply. The most recent datat item is added to the end. In order to sort and use finding algos on the list there must be 2 pointers, whilst I've declared the 2 points to NULL I cant figure out how to use trailing pointers....

Acidburn
Posting Pro
511 posts since Dec 2004
Reputation Points: 12
Solved Threads: 5
 

[php] #include

using namespace std;

typedef struct Template { int a; Template * link; // goes forward (one way reference) } list;

typedef list * listptr;

int main() { listptr head; // head is a type listptr listptr p ; listptr next ;

head = NULL; //therfore make it null next = NULL;

for(int i =0 ; i<4 ; ++i) { p = new list;// create new element of p type of listptr (new structure) cin >> p->a;

cout << p->a <link = next; cout << p <

Hey dude i can give u the c code for that problem if u want but in C++ i have not clear funsdas///

akshatvig19
Newbie Poster
2 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You