Skip to content

Instantly share code, notes, and snippets.

@oguzhanvarsak
Created October 19, 2018 09:39
Show Gist options
  • Save oguzhanvarsak/cda4e194b08a76e3dae4a820e4f2226e to your computer and use it in GitHub Desktop.
Save oguzhanvarsak/cda4e194b08a76e3dae4a820e4f2226e to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node *next;
struct node *prev;
}*head=NULL;
struct node *yeniNodeOlustur(int gelen){
struct node *yeniNode = (struct node*)malloc(sizeof(struct node));
yeniNode->data = gelen;
yeniNode->next = NULL;
yeniNode->prev = NULL;
return yeniNode;
}
void ekle (int gelen);
void bastanSonaYazdir ();
void sondanBasaYazdir ();
int main() {
ekle(434);
ekle(6);
ekle(94);
ekle(414);
bastanSonaYazdir();
sondanBasaYazdir();
}
void ekle (int gelen) {
struct node *temp = head;
struct node *yeniNode = yeniNodeOlustur(gelen);
if (head == NULL) {
head = yeniNode;
return;
}
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = yeniNode;
yeniNode->prev = temp;
}
void bastanSonaYazdir () {
struct node *temp = head;
printf("Bagli Liste (Duz): ");
while (temp!= NULL) {
printf("%d ",temp->data);
temp = temp->next;
}
printf("\n\n");
}
void sondanBasaYazdir () {
struct node* temp = head;
if(temp == NULL) {
return;
}
while(temp->next != NULL) {
temp = temp->next;
}
printf("Bagli Liste (Tersten): ");
while(temp != NULL) {
printf("%d ",temp->data);
temp = temp->prev;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment