Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include "Header.h"
- using namespace std;
- template <typename T>
- struct linkNode {
- int data;
- linkNode<T> *nextNode;
- };
- template <typename T>
- class headNode {
- private:
- linkNode<T> *head, *tail;
- public:
- int sizeList;
- headNode() {
- head = nullptr;
- tail = nullptr;
- }
- void sort() {
- int counter = 0;
- linkNode<T> *tempHead = head;
- T *tempNode = 0;
- while (tempHead != nullptr && tempNode != nullptr) {
- tempHead = tempHead->nextNode;
- counter++;
- for (int i = 0; i < counter; i++) {
- for (int j = 0; j < counter; j++) {
- if (tempHead->data > tempHead->nextNode->data) {
- *tempNode = tempHead->data;
- tempHead = tempHead->nextNode;
- tempHead->nextNode->data = *tempNode;
- }
- }
- }
- }
- }
- void addNode(T userData) {
- linkNode<T> *tempNode = new linkNode<T>;
- tempNode->data = userData;
- tempNode->nextNode = nullptr;
- if (head == nullptr) {
- head = tempNode;
- tail = tempNode;
- tempNode = nullptr;
- }
- else {
- tail->nextNode = tempNode;
- tail = tempNode;
- }
- sizeList++;
- }
- void display() {
- linkNode<T> *tempNode = new linkNode<T>;
- tempNode = head;
- while (tempNode != nullptr) {
- cout << tempNode->data << endl;
- tempNode = tempNode->nextNode;
- }
- }
- T at(int userInput) {
- linkNode<T> *tempNode = new linkNode<T>;
- tempNode = head;
- if (sizeList != 0) {
- for (int i = 0; i < sizeList; i++) {
- if (i == userInput) {
- break;
- }
- tempNode = tempNode->nextNode;
- }
- return tempNode->data;
- }
- else {
- cout << "Link List Empty" << endl;
- }
- }
- };
- class listData {
- public:
- string listOne = "10, 22, 34, 45, 48, 55, 56, 57, 57, 69, 70, 72, 74, 74, 80, 83, 84, 85, 88, 88";
- string listTwo = "50, 55, 57, 79, 81, 84, 87, 88, 90, 92, 95, 95, 95, 96, 99";
- vector<string> vectorOne;
- vector<string> vectorTwo;
- headNode<int> finalList;
- double average;
- int listSum;
- headNode<int> realFirstList;
- headNode<int> realSecondList;
- listData() {
- vectorOne = cStringSplit(listOne, ", ");
- vectorTwo = cStringSplit(listTwo, ", ");
- finalList = convert(vectorOne, vectorTwo);
- showSum();
- }
- void run() {
- for (int i = 0; i < 20; i++) {
- realFirstList.addNode(rand() % 100 + 0);
- }
- for (int i = 0; i < 15; i++) {
- realSecondList.addNode(rand() % 100 + 0);
- }
- }
- headNode<int> convert(vector<string> first, vector<string> second) {
- headNode<int> returnObject;
- for (int i = 0; i < first.size(); i++) {
- returnObject.addNode(String2Int(first[i]));
- }
- for (int i = 0; i < second.size(); i++) {
- returnObject.addNode(String2Int(second[i]));
- }
- return returnObject;
- }
- void showSum() {
- for (int i = 0; i < finalList.sizeList; i++) {
- listSum = listSum + finalList.at(i);
- }
- for (int i = 0; i < finalList.sizeList; i++) {
- average = listSum / finalList.sizeList;
- }
- finalList.sort();
- cout << "test" << endl;
- finalList.display();
- }
- void displayMess() {
- cout << "Result:" << endl << listOne << ", " << listTwo;
- cout << endl;
- cout << endl << "The sum of the final list's element is: " << listSum << endl;
- cout << "The average of the final list's elemets is:" << average << endl << endl;
- }
- };
- void main() {
- listData temp;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment