阅读双重链表n位置

时间:2017-10-27 07:49:43

标签: linked-list doubly-linked-list

我的双向链表包含abc ... z。这是从第一个文件中读取的.. 我的第二个文件包含int 4,10,8,-3。 根据我的第二个文件,我想在屏幕上显示abc..z .. 4 - >我要前进到D然后10 - >更多,直到N,然后...... 我怎样才能做到这一点?请任何帮助.. anyhlep真的很适合..

 #include <iostream>
#include <fstream>
using namespace std;
class Myclass{

public:
void putItem(char cha);
void printItme();
void getIndex(int);
Myclass();

private:
struct Node
{
    char aplBat;
    Node *next;
    Node *prev;
};
Node *head;
int potionIndex = 0;

};
int main(){
ifstream inputFile, inputInt;
Myclass obj;
string stringInt;
double valData = 0;
int total = 0;
char charData;
/*my first file with alpa */
inputFile.open("Letters.txt");
if(inputFile.good())
{
    while(inputFile >> charData)
    {
        obj.putItem(charData);
    }
  }
  else
    cout << "Error " << endl;
inputFile.close();
//From right here.. I am reading data from file Sequence, 3,5,-2,10,-5
inputInt.open("Sequence.txt");
if(inputInt.good())
{

    while(getline(inputInt, stringInt, ',')){

        valData = atof(stringInt.c_str());
        total += valData;
        obj.getIndex(total);
    }
    //cout << "Total " << total << endl;
    cout << "FIle ok " << endl;
    obj.printItme();
}
else
    cout << "Error " << endl;
inputInt.close();
cout << endl;
return 0;
}
 void Myclass::putItem(char cha){
Node *newNode;
newNode = new Node;
newNode->aplBat = cha;
newNode->prev = nullptr;
newNode->next = nullptr;

if(!head)
{
    head = newNode;
}
else
{
    head->prev = newNode;
    newNode->next = head;
    head = newNode;
}
}
void Myclass::printItme()
 {
  Node *temp = head;
if(temp == nullptr)
{
    cout << "Empty List " << endl;
}
while(temp->next != nullptr)
{
    temp = temp->next;
}
while(temp->prev != nullptr)
{
    cout << temp->aplBat << " ";
    temp = temp->prev;
}
cout << "Repitation " << potionIndex << endl;
}
Myclass::Myclass()
{
head = nullptr;
}
void Myclass::getIndex(int val)
{
 potionIndex = val;
}

0 个答案:

没有答案