Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
int a[5][5];
int nnz = 0;
cout <<"Non Sparse Matrix Array is ->\n";
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
int val = rand() % 10;
a[i][j] = (val % 2 == 0) ? val * 10 : 0;
if (a[i][j] != 0)
nnz++;
cout << a[i][j] <<"";
}
}
return 0;
}
class Stack {
int top;
int A[MAX];
public:
Stack() {
top = -1;
}
bool IsEmpty();
bool IsFull();
void Push(int);
int Pop();
};
bool Stack::IsEmpty() {
if (top<= -1)
return true;
return false;
}
bool Stack::IsFull() {
if (top>= MAX - 1)
return true;
return false;
}
int Stack::Pop() {
if (!IsEmpty()) {
return A[top--];
}
}
struct node {
int info;
node *next;
};
class SLL {
public:
SLL();
SLL(const SLL& orig);
virtual ~SLL();
bool IsEmpty();
void Create(int val);
void Insert_beg(int val);
void Insert_end(int val);
void Insert_pos(int val);
int Delete_beg();
int Delete_end();
void Destory();
void Traverse();
private:
node *list;
};
#include"SLL.h"
#include<iostream>
using namespace std;
SLL::SLL() {
list = NULL;
}
SLL::~SLL() {
Destory();
}
bool SLL::IsEmpty() {
if (list == NULL) {
return true;
return false;
}
}
int SLL::Delete_beg() {
int val = -1;
if (!IsEmpty()) {
node *q = list;
list = list->next;
val = q->info;
delete q;
}
return val;
}
int SLL::Delete_end() {
int val = -1;
if (!IsEmpty()) {
if (list->next != NULL)
val = Delete_beg();
else {
node *q = list;
while (q->next != NULL)
q = q->next;
node *p = q->next;
q->next = NULL;
val = p->info;
delete p;
}
}
return val;
}
void SLL::Traverse() {
if (!IsEmpty()) {
node *q = list;
while (q != NULL) {
cout << q->info<<"->";
q = q->next;
}
cout <<"NULL\n";
}
}
void SLL::Destory() {
if (!IsEmpty()) {
Delete_beg();
}
}