#include <stdio.h> #include <stdlib.h> #include <malloc.h> struct LLNode { int index; int data; struct LLNode *next; }; void push(struct LLNode **t, int i) { int value; struct LLNode *temp; temp = (struct LLNode *)malloc(sizeof(struct LLNode)); printf("\n Push Data : "); scanf("%d",&value); temp->data=value; temp->index=i; temp->next = *t; *t = temp; } void pop(struct LLNode **t) { struct LLNode *temp; if(*t == NULL) printf("\nStack is Empty\n"); else { temp=*t; *t=temp->next; } } int main() { int select, i=1; struct LLNode *head, *tail; head=NULL; printf("\n 1->Push \t\n 2->Pop \t\n 3->Exit\n Select :"); scanf("%d",&select); while(select!=3) { switch(select) { case 1: push(&head,i); i++; tail=head; printf("\nIndex | data\n"); printf("================\n"); while(tail!=NULL) { printf("%d | %d\n", tail->index, tail->data); tail=tail->next; } break; case 2: pop(&head); tail=head; printf("\nIndex | data\n"); printf("================\n"); while(tail!=NULL) { printf("%d | %d\n", tail->index, tail->data); tail=tail->next; } break; default: break; } printf("\n\n 1->Push \t\n 2->Pop \t\n 3->Exit\n Select :"); scanf("%d",&select); } return 0; }
Rabu, Mei 29, 2013
C : Linked List Stack (Push & Pop)
Label:
C/C++,
FSKTM,
Pengaturcaraan,
UTHM
Langgan:
Catat Ulasan (Atom)
0 ulasan:
Catat Ulasan
Selamat datang ke 0x2013LΣΣT. Sekiranya anda mempunyai persoalan, pandangan, permintaan, bantuan, cadangan dan sebagainya. Tinggalkan pesanan anda ke dalam kotak komen. Terima kasih !
- http://0x2013.blogspot.com -