Using singly and doubly linked lists do the following :
(1)create a class that implements the following :
a->abdullah->ali
b->ball->bill
c->cat->cute
d->dark->dog
Note:
a, b, c and d are connected using doubly links and rest of the links are all singly links.
(2)no global declarations are allowed
(3)run test the code in main
(4)make a menu
#include <iostream>
using namespace std;
struct node {
char data;
node* next;
};
node* add(char data)
{
node* newnode = new node;
newnode->data = data;
newnode->next = NULL;
return newnode;
}
node* string_to_linked_list(string text, node* head)
{
head = add(text[0]);
node* curr = head;
for (int i = 1; i < text.size(); i++) {
curr->next = add(text[i]);
curr = curr->next;
}
return head;
}
void print(node* head)
{
node* curr = head;
while (curr != NULL) {
cout << curr->data << " -> ";
curr = curr->next;
}
}
int main()
{
string text = "ABDULLAH";
node* head = NULL;
head = string_to_linked_list(text, head);
print(head);
return 0;
}
Comments
Leave a comment