Showing posts with label display. Show all posts
Showing posts with label display. Show all posts

Friday, February 13, 2015

C Program for Array Representation of Stack Push Pop and Display


What is Stack?
Stack is a LIFO (last in first out) structure. It is an ordered list of the same type of elements. A stack is a linear list where all insertions and deletions are permitted only at one end of the list. When elements are added to stack it grow at one end. Similarly, when elements are deleted from a stack, it shrinks at the same end.

Also Read: C++ program to perform a PUSH operation on a dynamically allocated stack
Also Read: Menu Driven C Program to Perform Insert, Display and Delete Operations on a Singly Linked List (SLL)

Below I have written a C program that performs push, pop and display operations on a stack. It is implemented using 1-D array.

C Program for Array Representation of Stack [Push]

C Program for Array Representation of Stack [Delete]

  C Program for Array Representation of Stack [Display]

#include<stdio.h>
#include<conio.h>
#include<process.h>       //for exit()
#include<stdlib.h>         //for system("cls")

#define MAX 5               //Maximum number of elements that can be stored

int top=-1,stack[MAX];
void push();
void pop();
void display();

void main()
{
    int ch;
    while(1)                //infinite loop, will end when choice will be 4
    {
        system("cls");      //work in windows, for other OS change it to system("clear")
        printf("*** Stack Menu ***");
        printf("

1.Push
2.Pop
3.Display
4.Exit");
        printf("

Enter your choice(1-4):");
        scanf("%d",&ch);

        switch(ch)
        {
            case 1: push();
                    break;
            case 2: pop();
                    break;
            case 3: display();
                    break;
            case 4: exit(0);

            default: printf("
Wrong Choice!!Press any key....");
                     getch();
        }
    }
}


void push()
{
    int val;
    if(top==MAX-1)
    {
        printf("
Stack is full!!Press any key....");
        getch();
    }
    else
    {
        printf("
Enter element to push:");
        scanf("%d",&val);
        top=top+1;
        stack[top]=val;
        printf("
Press any key....");
        getch();
    }
}


void pop()
{
    if(top==-1)
    {
        printf("
Stack is empty!!Press any key....");
        getch();
    }
    else
    {
        printf("
Deleted element is %d
Press any key....",stack[top]);
        top=top-1;
        getch();
    }
}


void display()
{
    int i;
    if(top==-1)
    {
        printf("
Stack is empty!!Press any key....");
        getch();
    }
    else
    {
        printf("
Stack is...
");
        for(i=top;i>=0;--i)
            printf("%d
",stack[i]);

    printf("
Press any key....");
    getch();
    }
}

Tuesday, January 13, 2015

How to restore Ubuntu 12 04 display resolution


Ubuntu 12.04 can lose its display resolution if it can no longer detect your display device. For example, the next time you boot your Ubuntu 12.04 PC, you might find that your display resolution has switched from 1280 x 960 to 800 x 600, which is nearly useless. Fortunately, this happens only rarely. In case you should be not so lucky, this document defines display resolution and explains how you might restore it in your Ubuntu 12.04 PC.
Note: Although this document applies specifically to Ubuntu 12.04, it also applies generally to other Ubuntu releases.
Defining display resolution
A 1280 x 960 (1280 columns by 960 rows of pixels) resolution displays 1,228,800 total pixels. In contrast, an 800 x 600 resolution displays only 480,000 total pixels, which reduces overall display resolution by 61%. For more information, please see Resolution, by Ted Hewitt at Riverside Community College.
Restoring Ubuntu 12.04 display resolution
If you lose normal display resolution on your Ubuntu 12.04 PC, you might restore your resolution by re-enabling display detection as follows:
  1. Turn off your display, and then disconnect its AC power cord.
  2. After waiting longer than 15 seconds, reconnect the AC power cord to your display, and then turn it on.
  3. Reboot your Ubuntu 12.04 PC.
  4. As shown in Figure 1 below, in the launcher, click the System Settings icon to display its window.
  5. As shown in Figure 2 below, in the Hardware section, click the Displays icon to display its window.
  6. Click Detect Displays to detect your display.
  7. Select a resolution, such as 1280 x 960 (4:3), and then click Apply to change the resolution.
  8. If you like your selected resolution, click Keep This Configuration to display a window similar to Figure 3 below.
Note: For additional information about trouble-shooting Ubuntu display resolution, please see Why cant Ubuntu 12.04 detect my screen resolution?.

Figure 1 - Clicking the System Settings icon in the launcher.
Figure 2 - Clicking the Displays icon in the System Settings window. 
Figure 3 - This is the Displays window for an example restored resolution.