Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <cstdlib>
  7.  
  8. using namespace std;
  9.  
  10. struct lista_elem{
  11.     int value;
  12.     lista_elem * next;
  13. };
  14.  
  15. typedef struct lista_elem item;
  16.  
  17. int _tmain(int argc, _TCHAR* argv[])
  18. {
  19.     item *current, *head;
  20.  
  21.     head = NULL;
  22.  
  23.     for (int i = 0; i < 10;i++)
  24.     {
  25.         current = new lista_elem;
  26.         current->value = i + 1;
  27.         current->next = head;
  28.         head = current;
  29.         cout << i + 1 << "Head: " << head->value << endl;
  30.         cout << i + 1 << "Head address: " << head << endl;
  31.         cout << i + 1 << "Current: " << current->value << endl;
  32.         cout << i + 1 << "Current address: " << current << endl << endl;
  33.     }
  34.     current = head;
  35.     cout << "Current: " << current->value << endl;
  36.  
  37.     while (current)
  38.     {
  39.         switch (current->value)
  40.         {
  41.         case 2: break;
  42.         case 5: current->value = 14; cout << current->value << " "; break;
  43.         default: cout << current->value << " "; break;
  44.         }
  45.  
  46.         current = current->next;
  47.     }
  48.     cout << endl << endl;
  49.     system("pause");
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement