0% found this document useful (0 votes)
3 views

Include

Uploaded by

Dima Azzam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Include

Uploaded by

Dima Azzam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <stdio.

h>
#include <malloc.h>

typedef struct Node{

int val;
struct Node *next;

}Node;

void add(Node *head, int number){

Node *newNode = (Node*)malloc(sizeof(Node));


newNode->val = number;
newNode->next = NULL;

Node *dummy = head;

if(head == NULL){
head = newNode;
}
else{
while(dummy->next != NULL){
dummy = dummy->next;
}
dummy->next = newNode;
}

int count(Node *head, int number){

Node *dummy = head;


int count = 0;

while(dummy != NULL){
if(dummy->val == number) number++;
dummy = dummy->next;
}

void REMOVE(Node *head, int number){

Node *dummy = head;


while(dummy->val == number){
head = dummy->next;
dummy = dummy->next;
}

Node *prev = dummy;


dummy = dummy->next;

while(dummy != NULL){

if(dummy->val == number){
prev->next = dummy->next;
free(dummy);
dummy = prev->next;
}
else{
prev = prev->next;
dummy = dummy->next;
}

Node* removeRecursive(Node *head, int number){

if(head == NULL){
return NULL;
}

Node *newList = removeRecursive(head->next, number);

if(head->val != number){
head->next = newList;
return head;
}

free(head);
return newList;

void reshape(Node *head){


Node *dummy = head;
int num = 0;

while (head != NULL){


num = dummy->val;
if(count(dummy, dummy->val) >= 2){
dummy = dummy->next;
dummy = removeRecursive(dummy, num);
}
}

// void reshape(Node *head){

// }

void print(Node *head){


Node *dummy = head;
while (dummy != NULL){
printf("%i\n", dummy->val);
}
}

int main(){

Node *head = malloc(sizeof(Node));


Node *dummy = head;

for (int i = 0; i < 10; i++){

Node *Gay = malloc(sizeof(Node));

if( i % 2 == 0){
Gay->val = 2;
}
else{
Gay->val = 1;
puts("Gay");
}

dummy->next = Gay;
dummy = dummy->next;

dummy->next = NULL;

print(head);

return 0;

}
#include <stdio.h>
#include <malloc.h>

int *readDims(){

int rows = 0;
printf("Number of rows : ");
scanf("%d", &rows);
printf("%d\n", rows);

int cols = 0;
printf("Number of cols : ");
scanf("%d", &cols);
printf("%d\n", cols);

int *dim = (int*)malloc(sizeof(int) * 2);


*(dim + 0) = rows;
*(dim + 1) = cols;

return dim;

float *createMat(){

int *A = readDims();
int rows = *(A + 0);
int cols = *(A + 1);
printf("%d\n", rows);
printf("%d\n", cols);

float *matrix = (float*)malloc(sizeof(float) * rows * cols);

return matrix;
}

void readMat(float *mat){

int *dim = readDims();


int rows = *(dim + 0);
int cols = *(dim + 1);

for(int i = 0; i < rows; i++){


for(int j = 0; j < cols; j++){
scanf("%d", mat + i * cols + j);
}
}

float *sumMat(float *mat1, float *mat2){

float *mat3 = createMat();


int *A = readDims();
int rows = *(A + 0);
int cols = *(A + 1);

for(int i = 0; i < rows; i++){


for(int j = 0; i < cols; j++){
int index = i * cols + j;
*(mat3 + index) = *(mat1 + index) + *(mat2 + index);
}
}

return mat3;

void printMat(float *mat){

int *A = readDims();
int rows = *(A + 0);
int cols = *(A + 1);

for(int i = 0; i < rows; i++){


for(int j = 0; i < cols; j++){
printf("%d \t", mat + i * cols + j);
}
printf("\n");
}

int main(){

return 0;

You might also like