I am trying to grasp the concept of linked list and how they connect by reading in a word 'bob' ...Is this correct or do i need to create another node?:
struct nodeIt {
char letter;
int occurences;
nodeIt * next;( this points to the next pointer correct?)
};
nodeIt * fromString(string word)//<----function
{
int i = 0;
list1 = new NodeIt;//gives first list1 address?
// Does the line above create a new node for me to store each letter
iter = list1;
while (iter != NULL) {
iter->letter = word[i];//storing 1st letter
iter->next->letter = word[i + 1];//not sure why this will not work
}
return list1;
the struc node should contain a template T value, and a Node* next; for the list class you have two nodes head and tail. in the constructor link them : head->next = tail; make sure that tail is always null.
create two method insert and remove that take as parameter a templated T value. make another method call find(value) . that would be a good start . the concpt is the link or see it like a chain or a necklace. you dont want it broken, make sure all node ar attached, at any time , mostly when you remove an element.
sorry for the confusion the syntax is confusing me:
there are no classes here just a struct and a function..or are you saying i need to make a class?
<would you have a link that i could read, im having a hard time grasping when to use the syntax proper and what it means>
node *list1 is head? or do i need to make a node* head
list1 = new Node = middle/iterator
what is
iter=list1 than?
Thanks allot,
i have a much better idea of what is going on now.
Or so i thought:\; I am getting out of range error after type in the word, compiler prompts me to abort:
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
struct orderNode {
char letter;
int occurence;
orderNode* next;
};
orderNode *fromString(string word);
int main() {
orderNode*list1;
string word1, word2;
cout << " Enter first word :" << word1;
cin >> word1;
list1 = fromString(word1);
system("pause");
return 0;
}
orderNode *fromString(string word) {
int i = 0;
orderNode *list1;//head
orderNode *n;//iter
orderNode *t;//tail
n = new orderNode;
list1 = n;
t = n;
n->letter = word[0];
while (n != NULL) {
n->letter = word[i];
n=new orderNode;
t->next = n;
t = t->next;