Lab 1 Poo Ilie
Lab 1 Poo Ilie
Lab 1 Poo Ilie
Departamentul
REFERAT
la lucrarea de laborator nr.1
Chișinău 2019
Sarcina lucrarii:
a) Scrieti un program care converteste un intreg intr-un numar octal.
a)
#include <iostream>
#include<cmath>
int main()
int decimalNumber;
cin>>decimalNumber;
return 0;
while(decimalNumber!=0)
rem=decimalNumber % 8;
decimalNumber /=8;
octalNumber+=rem*i;
i*=10;
}
return octalNumber;
b)Scrieti un program care roteste fiecare element al listei dublu lantuite la dreapta cu b pozitii.
#include<bits/stdc++.h>
using namespace std;
struct Node {
char data;
struct Node*prev;
struct Node*next;
};
void rotate(struct Node**head_ref, int N)
{
if (N==0)
return;
struct Node*current=*head_ref;
int count= 1;
while (count < N && current !=NULL) {
current= current->next;
count++;
}
if (current ==NULL)
return;
struct Node*NthNode = current;
while(node->next !=NULL) {
cout<<node->data<< ""
<<"<=>"
<<"";
node = node->next;
}
cout << node->data;
}
int nk=0;
char elem;
int main(void)
{
struct Node* head = NULL;
cout << "Dati nr. de elemente: ";
cin >> nk;
for(int i = 0; i < nk; i++){
cout<<"Dati elementele: ";
cin>>elem;
push(&head, elem);
}
int N;cout << "Dati N:";
cin >> N;
cout<<"Given linked list \n";
printList(head);
rotate(&head,N);