Ask your own question, for FREE!
Mathematics 7 Online
OpenStudy (anonymous):

Write a program in three parts. The first part should create a linked list of 26 nodes. The second part should fill the list with the letters of the alphabet. The third part should print the contents of the linked list.

OpenStudy (anonymous):

How far have you gotten what do you have down with regards to linked list? I can give you the pseudocode break down but it won't do good if I'm telling you something you should pretty be familiar with.

OpenStudy (anonymous):

#include <iostream> using namespace std; int main() struct node { int value; node*next; } { node*top; top=new node; (*top).value=1 (*top).next=new node;

OpenStudy (anonymous):

any help will be greatly appreciated

OpenStudy (anonymous):

Looks like you got most of it down what do you feel you're confused about? All that's really next is to create a node linked list of the alphabet by creating a node called alphabet where the first node in the list is A then that points to the next.node B which points to C... You get the point.

OpenStudy (anonymous):

so that was the second part?

OpenStudy (anonymous):

Yep you already have your node struct to that allows you create other nodes which then form a connection to eachother which as a result forms linked list of nodes. Now within your node struct you have 2 objects. an int called value and another pointer to a node called next. All you have to do now is fill each one individually and link them.

OpenStudy (anonymous):

struct item { int data; item *next; }; int main() { item*first,*current first=new item; (*first).data=1; current=first; for (i=2; i<=100; i++) { (*current).next=new item; current=(*current).next; (*current).next=NULL; } what does this code mean?

OpenStudy (anonymous):

Did you write it or did you copy it? If so what does the book say? Let's work from there, give me your rough understanding. Anything would help.

OpenStudy (anonymous):

I copied it from the board

OpenStudy (anonymous):

those were the notes for that assignment

OpenStudy (anonymous):

#include <iostream> using namespace std; struct item { int data; item *next; }; int main() { item*first*current; //Creating a item called first and current first = new item; //set some memory on the stack for first (*first).data = 1; //set our first data field to 1 current = first; //as of right now current is first for(i=2;i<100;i++)//creating a linked list of numbers 1 -100 {//BEGIN THE LIST (*current).next = new item;//have current point to our new item (****Wait huh? why we still haven't put anything in current...<-hint current=(*current).next;//Okay lets move to the next node in the list (*current).next = NULL; //END THE LIST } }

OpenStudy (anonymous):

let me know what confuses you logically.

OpenStudy (anonymous):

for(i=2;i<100;i++) so should I change this to for(i=2;i<26;i++)

OpenStudy (anonymous):

Why not go ahead and let i be a char which holds the values from 'A' - 'Z' because if we look at the ascii table A-Z is 26 letters total, so that should take care of the size. And snce our counter i is now a char we can go ahead set our data to i within the forloop.

OpenStudy (anonymous):

oh ok, thanks for the help

OpenStudy (anonymous):

Anytime let me know if you have any confused I enjoy the functionality of nodes. They're awesome.

OpenStudy (anonymous):

ok, thanks. I appreciate it.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!