SHARE
TWEET

Untitled

a guest Mar 26th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Ma'sum Abdul Wadud
  2.  * Lab 7
  3.  * CSC 230 Section 01
  4.  */
  5.  
  6.  
  7. #include <iostream>
  8. #include <string>
  9. #include <fstream>
  10.  
  11. using namespace std;
  12.  
  13. struct node{
  14.   string fullName;
  15.   string ssn;
  16.   node* next;
  17.   node* prev;
  18. };
  19.  
  20. void search(node* head, string userSSN){
  21.   int count = 0;
  22.  
  23.   while(head != NULL){
  24.     if(userSSN.compare(head->ssn) == 0){
  25.       cout << "Found at location: " << count << "\n" << endl;
  26.     }
  27.     head = head->next;
  28.     count++;
  29.   }
  30. }
  31.  
  32. void append(node*& head, string userSSN, string name)
  33. {
  34.   node* newNode = new node;
  35.   newNode->ssn = userSSN;
  36.   newNode->fullName = name;
  37.   newNode->next = NULL;
  38.   //newNode -> prev = NULL;
  39.  
  40.   if(head == NULL)
  41.     {
  42.       head = newNode;
  43.     }
  44.  
  45.   else
  46.     {
  47.     node* temp = head;
  48.     while(temp -> next != NULL){
  49.         temp = temp -> next;
  50.     }
  51.     temp -> next = newNode;
  52.     }
  53. }
  54.  
  55. void insert(node*& head, node*& tail, string userSSN, string name){
  56.     if(head == NULL){
  57.         head = new node;
  58.         head->next = NULL;
  59.         head->prev = NULL;
  60.  
  61.         head->ssn = userSSN;
  62.         head->fullName = name;
  63.     }
  64.  
  65. else if((head->ssn) > userSSN){
  66.     node* temp = new node;
  67.     temp->next = head;
  68.     temp->prev = NULL;
  69.     head->prev = temp;
  70.     head = temp;
  71.  
  72.     head->ssn = userSSN;
  73.     head->fullName = name;
  74. }
  75.  
  76. else{
  77.     node* temp = head;
  78.     while(temp->next != NULL){
  79.         if((temp->ssn < userSSN) && ((temp->next)->ssn) > userSSN){
  80.             break;
  81.         }
  82.         temp = temp->next;
  83.     }
  84.  
  85.     if(temp->next == NULL){
  86.         node* current = new node;
  87.         temp->next = current;
  88.         current->prev = temp;
  89.         current->next = NULL;
  90.  
  91.         current->ssn = userSSN;
  92.         current->fullName = name;
  93.     }
  94.     else{
  95.         node* following = temp->next;
  96.         node* current = new node;
  97.         temp->next = current;
  98.         following->prev = current;
  99.         current->next = following;
  100.         current->prev = temp;
  101.  
  102.         current->ssn = userSSN;
  103.         current->fullName = name;
  104.  
  105.     }
  106. }
  107. }
  108.     /*if((newPtr->ssn) < (head->ssn)){
  109.         newPtr->prev = NULL;
  110.         head->prev = newPtr;
  111.         newPtr->next = head;
  112.         head = newPtr;
  113.         //return;
  114.     }
  115.  
  116.     if((newPtr->ssn) > (tail->ssn)){
  117.  
  118.     }
  119.     else{
  120.         newPtr = new node;
  121.         newPtr->ssn = userSSN;
  122.         newPtr->fullName = name;
  123.         newPtr->prev = tail;
  124.         tail->next = newPtr;
  125.         tail = newPtr;
  126.     }
  127.     tail->next = NULL;
  128. }*/
  129.  
  130.  
  131.  
  132.  
  133. void print(node*& head){
  134.   node* tmp = head;
  135.  
  136.   while(tmp != NULL){
  137.     cout << tmp->ssn << endl;
  138.     tmp = tmp->next;
  139.   }
  140. }
  141.  
  142.  
  143. int main(int argc, char* argv[]){
  144.   fstream input(argv[1]);
  145.   string i, s, f, l;
  146.   string userSSN;
  147.   string personName;
  148.  
  149.   int count = 0;
  150.   node* headPtr;
  151.   node* tailPtr;
  152.  
  153.   while(!input.eof()){
  154.     input >> i >> s >> f >> l;
  155.     personName = f + " " + l;
  156.     userSSN = s;
  157.  
  158.     insert(headPtr, tailPtr, userSSN, personName);
  159.     count++;
  160.  
  161.     if(!input){
  162.       break;
  163.     }
  164.   }
  165.   input.close();
  166.   cout << "\nInput a Social Security Number: " << endl;
  167.   cin >> userSSN;
  168.  
  169.   //search(headPtr, tailPtr, userSSN);
  170.   print(headPtr);
  171.  
  172.   return 0;
  173. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top