Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Modify the code so it prints the alphabet backwards and forwards using the next and prior pointers in the doubly linked list. Code: //

C++

Modify the code so it prints the alphabet backwards and forwards using the next and prior pointers in the doubly linked list.

Code:

// LL.cpp : Defines the entry point for the console application. //

#include "stdafx.h" #include #include

using namespace std;

class node { public: char data; node* next; node(); };

node::node() {

}

int _tmain(int argc, _TCHAR* argv[]) { char s[] = "abcdefghijklmnopqrstuvwxyz";

node* head; node* temp; node* current;

head = new node; // create the head of the linked list head->data = s[0]; head->next = NULL; temp = head; // get ready for the loop - save the head in temp - you are going to change temp in the loop

for (size_t i = 1; i < strlen(s); i++) // create the rest of the linked list { current = new node; // make a new node current->data = s[i]; // set it's data member current->next = NULL; temp->next = current; // point to the new node temp = current; // make temp point to current node (for next time through) }

node* ptr = head; // set a ptr to head, then you are going to "increment" the pointer

while (ptr != NULL) { cout << ptr->data; // print out the linked list ptr = ptr->next; // increment the linked list }

cout << endl; system("pause"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago